gpt4 book ai didi

android explicit intent by name 不解析其他 Activity

转载 作者:太空宇宙 更新时间:2023-11-03 10:35:31 25 4
gpt4 key购买 nike

我有 2 个应用程序相互配合使用。我想创建一个从应用程序 B 启动应用程序 A 的按钮,因此我在应用程序 B 中创建了一个类似这样的 Intent :

Intent intent = new Intent("com.org.orgmobile.android.action.ACTION_CUSTOM");
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setData(Uri.parse(url));
startActivity(intent);

urlhttps://org.org.com/mobile/Support/action/org/ActionEnumValue/?a=123

我在应用程序 A 的 list 中声明的​​ Intent 过滤器是这样的:

<intent-filter>
<action android:name="com.org.orgmobile.android.action.ACTION_CUSTOM"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="https"/>
<data android:host="org.org.com"/>
<data android:pathPrefix="/mobile/Support/action/${manifestplaceholderattr}.*/ActionEnumValue/*"/>
</intent-filter>

manifestplaceholderattr是一个空字符串。

我得到了

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.org.orgmobile.android.action.ACTION_CUSTOM dat=https://org.org.com/... flg=0x20000000 }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1936)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1615)
at android.app.Activity.startActivityForResult(Activity.java:4472)
at android.app.Activity.startActivityForResult(Activity.java:4430)
at android.app.Activity.startActivity(Activity.java:4791)
at android.app.Activity.startActivity(Activity.java:4759)

我在这里忽略了什么?我尝试使用 pathPattern 而不是路径前缀,但没有成功。

编辑:为了提供更多详细信息,我不只是想启动该特定 Activity ,我还想匹配与该 Activity 关联的特定 Intent 以启动该 Activity 。我不想直接启动该 Activity ,因为在这种情况下,用户的应用程序已过时,因为它不会具有所需的行为。

最佳答案

通过包管理器执行此操作的最佳方式如下。

 PackageManager manager = getPackageManager();
try {
Intent intent = manager.getLaunchIntentForPackage("app B package name here");
if (intent == null)
throw new PackageManager.NameNotFoundException();
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}

包管理器检查是否安装了具有给定包名称的应用程序,如果存在则启动应用程序,否则抛出 NameNotFoundException

关于android explicit intent by name 不解析其他 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46371933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com