gpt4 book ai didi

android - 使用 Intent 的 Action 启动 Activity 并将其限制在 App 内

转载 作者:行者123 更新时间:2023-11-29 19:44:10 24 4
gpt4 key购买 nike

我有 2 个应用程序,它们具有相同的包名称但包 ID 不同(在 gradle 配置中设置)。

通过在两个应用程序中设置一个 Intent 的操作字符串来启动一个 Activity ,这两个应用程序在两个应用程序中都是相同的。

这意味着如果我在同一台设备上安装了这两个应用程序,那么启动一个 Activity 会显示一个 Complete action using..要求用户选择一个 Activity 来完成操作的对话框。

我的问题是如何在不更改 list 文件中的字符串本身(其中很多是由于多个模块)和使用 startActivity() 之前设置操作字符串的情况下将它们分开本身在代码库中,以便操作仅限于当前应用程序?

更新#1:我们有没有更接近 intent.setPackage() 的东西?至于改用应用程序ID?

最佳答案

如果我没有误解您的问题,您可以通过以下代码将其存档:

// start exactly component
Intent intent = new Intent();
intent.setComponent(new ComponentName("yourPackageId", "yourPackageName.MainActivity"));
startActivity(intent);

//or you want to start launcher intent
Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage("yourPackageId");

您应该确保您的MainActivity 具有android:exported = true,如此处所述android:exported :

Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID.

关于android - 使用 Intent 的 Action 启动 Activity 并将其限制在 App 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38114376/

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