简体   繁体   English

[Android]context.startActvity(intent) 抛出 ActivityNotFoundException

[英][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 ):此外,还有多个关于如何启动外部活动的示例,可以查看这两个示例(示例的来源):

1. 1.

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);

2. 2.

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.

相关问题 Android ActivityNotFoundException意图 - Android ActivityNotFoundException Intent Android:StreetView意图导致ActivityNotFoundException - Android:StreetView intent causing ActivityNotFoundException Android - 活动和启动活动 - Android - Activity and startActvity 简单 https URI 意图上的 Android ActivityNotFoundException - Android ActivityNotFoundException on simple https URI Intent 使用Intent的android.content.ActivityNotFoundException - android.content.ActivityNotFoundException using Intent android.content.ActivityNotFoundException:将url传递给intent - android.content.ActivityNotFoundException: passing url to the intent Android Intent数据失败并且Intent解析返回ActivityNotFoundException - Android Intent data fails and intent resolution returns ActivityNotFoundException Android Studio startActvity需要权限 - Android Studio startActvity requires permission Android错误:“ android.content.ActivityNotFoundException:未找到用于处理Intent的活动” - Android error : “android.content.ActivityNotFoundException: No Activity found to handle Intent” Android:android.content.ActivityNotFoundException:找不到处理 Intent 的活动 - Android: android.content.ActivityNotFoundException: No Activity found to handle Intent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM