[英][Android]context.startActvity(intent) throwing ActivityNotFoundException
My use case is to switch from App1 to App2 .我的用例是从App1切换到App2 。 In App1, I use the packageManager.getPackageInfo() API to check whether the App2 is present or not.在 App1 中,我使用packageManager.getPackageInfo() API 来检查 App2 是否存在。 When it returns true, I set the intent with intent.setPackage(App2) and trigger the context.startActivity(intent) API.当它返回 true 时,我使用intent.setPackage(App2)设置意图并触发 context.startActivity(intent) API。 But there are times when context.startActivity(intent) API throws ActivityNotFoundException : App2 is present in the device.但有时context.startActivity(intent) API会抛出ActivityNotFoundException : App2 存在于设备中。 The intent has been set in App2 and android:exported is also set to true.意图已在 App2 中设置,并且 android:exported 也设置为 true。
This issue is happening from Android 12 .这个问题发生在Android 12 。 Any inputs be would be highly appreciated!任何输入将不胜感激!
There is an official documentation on how to prepare an Activity to be launched from outside of the app: https://developer.android.com/training/basics/intents/filters有一个关于如何准备从应用程序外部启动的活动的官方文档: https://developer.android.com/training/basics/intents/filters
Furthermore there are multiple examples on how to launch an external activity, maybe check out these two examples ( Source for the examples ):此外,还有多个关于如何启动外部活动的示例,可以查看这两个示例(示例的来源):
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (launchIntent != null) {
startActivity(launchIntent);//null pointer check in case package name was not found
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.