android - 在反应移动应用程序上设置应用程序链接
问题描述
我实际上正在制作一个移动应用程序,我会设置链接以在您单击它时打开它。我试图设置应用程序链接,但我似乎没有工作......这是我的代码:
清单.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.didierurban.testLenny">
...
<activity
android:name="MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
...
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https" android:host="example.net" />
</intent-filter>
</activity>
</application>
</manifest>
我的assetlink.json(在https://example.net/.well-known/assetlinks.json上)
// 20210407190840
// https://lenny-girardot.fr/.well-known/assetlinks.json
[
{
"relation": [
"delegate_permission/common.handle_all_urls"
],
"target": {
"namespace": "android_app",
"package_name": "com.didierurban.testLenny",
"sha256_cert_fingerprints": [
"D4:DC:31:60:E9:B2:3F:2B:DF:23:33:31:49:D3:10:9F:3C:3A:6F:E6:1D:41:6E:DB:17:A3:3E:DD:1C:9C:6A:46"
]
}
}
]
应用程序.json
{
"expo": {
"scheme": "...",
"name": "...",
"slug": "...",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "..."
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"package": "..."
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
如果应用程序链接无法与 React 一起使用,我可以设置什么使其正常工作?我也尝试使用https://www.npmjs.com/package/node-deeplink但它似乎已经过时了。
谢谢
解决方案
在博览会上,您首先需要scheme
在app.json
. 例如myawesomeapp
。
您的清单文件也应该具有与此相同的方案
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.didierurban.testLenny">
...
<activity
android:name="MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
...
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="myawesomeapp" />
</intent-filter>
</activity>
</application>
</manifest>
在 ios 上,将其添加到info.plist
此处
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>myawesomeapp</string>
</array>
</dict>
</array>
然后,您可以使用 url 打开指向您的应用程序的链接myawesomeapp://
您还可以签出此库以从您的 react 本机应用程序链接到其他应用程序
有关博览会中深度链接的更多信息,请在此处查看文档
推荐阅读
- google-sheets-formula - 根据数字显示费用的公式
- c - 使用 Mutex 或 Semaphor 修复程序的最大线程数
- python - Scrapy 未遵循所有链接和 xPath 未返回正确数据
- python - Flair Framework with PyTorch - OverflowError: int too big to convert
- html - 在 CSS 中创建一个聊天气泡,边框围绕 ::before 属性
- php - 卷曲的回声响应
- typescript - 使用 TypeScript 在 Vue 3 中创建全局过滤器
- python - 如何填充元组列表,使用 for 循环在 Python 中保留其结构?
- php - 如何迭代嵌套的 stdClass 对象?
- r - 将 tibble 与来自同一 tibble 的数据合并