是否可以从即时应用程序启动另一个应用程序?

Is it possible to launch another application from an instant app?

通常,当然,it's easygetLaunchIntentForPackage("com.package") 给出了一个 Intent,您可以将其传递给 startActivity()

但是当在免安装应用程序中执行时getLaunchIntentForPackage() returns null 即使安装了目标应用程序!

查看 comments 链接问题,我不是唯一遇到此问题或限制的人。但是,没有解决方案,似乎还没有关于此的问题。

有什么办法可以绕过这个限制吗?

浏览 Google Play Instant developer documentation 多了一点,我找到了解释:

Google Play Instant runs instant-enabled app bundles in a special kind of SELinux sandbox for added security. This sandbox permits a subset of permissions, as well as limited types of interactions with other apps.

更具体地说,在什么情况下其他应用程序可以被访问:

Access to installed apps

When developing an instant experience, keep in mind that it cannot interact with installed apps on a device unless one of the following is true:

  • One or more activities within an installed app has set its android:visibleToInstantApps element to trueThis element is available to apps running Android 8.0 (API level 26) or higher.
  • An installed app contains an intent filter that includes CATEGORY_BROWSABLE.
  • The instant experience is sending an intent using either the ACTION_SEND, ACTION_SENDTO, or ACTION_SEND_MULTIPLE action.

所以这解释了这一点并且看起来很合理。

我会调查其中一些是否适用于我的情况,稍后再报告...

编辑:是的,android:visibleToInstantApps 有效!

就我而言,我试图启动同一客户公司的另一个应用程序,这意味着我也可以控制该代码库。

在Android目标应用的Android清单中,将android:visibleToInstantApps="true"添加到其中一个活动。这适用于 Android 8 及更高版本,即使 minSdkVersion 更低也可以使用。