Android 14下React Native使用Linking.openUrl打开DeepLink报错求助
问题描述
在React Native应用中尝试打开DeepLink时触发错误:
[Error: Could not open URL 'micoope://app/cuenta/token': No Activity found to handle Intent { act=android.intent.action.VIEW dat=micoope://app/... }]
已知这是Android 14的新安全策略导致,但不确定是需要自己修改项目里的显式Intent创建(也不知道改哪个文件),还是该由React Native团队处理。附当前AndroidManifest文件中MainActivity的配置:
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="false" 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="micoope" android:host="app" /> </intent-filter> </activity>
解决步骤
- 修正
android:exported属性
Android 14要求所有包含Intent Filter的Activity必须设置android:exported="true"——因为这类Activity需要接收外部应用或系统发来的Intent。你当前的MainActivity配置里exported是false,这直接导致系统无法找到并启动它处理DeepLink。把这个属性改成true:
android:exported="true"
- 确认跳转逻辑(自定义场景)
如果是你自己在RN代码外实现了跳转逻辑,比如自定义原生模块,要确保用的是隐式Intent(DeepLink靠scheme匹配,不需要指定具体Activity类名)。Kotlin示例代码:
val intent = Intent(Intent.ACTION_VIEW).apply { data = Uri.parse("micoope://app/cuenta/token") addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } context.startActivity(intent)
如果用的是RN自带的Linking.openURL(),底层已经处理了Intent创建,不需要额外修改原生代码。
- 验证配置生效
修改AndroidManifest后重新打包安装,也可以用adb命令直接测试:
adb shell am start -W -a android.intent.action.VIEW -d "micoope://app/cuenta/token" com.your.package.name
替换com.your.package.name为你应用的包名,看是否能正常启动MainActivity。
说明
这个问题不需要React Native团队处理,是你项目的AndroidManifest配置不符合Android 14的安全要求导致的。修正exported属性就能解决核心问题,RN的DeepLink机制本身已经适配了Android 14规则。
内容的提问来源于stack exchange,提问作者Germán Sager
相关产品推荐
相关产品推荐

