处理权限:将大型应用中的一个 activity 变成免安装应用

Handling Permissions: Making one activity of a large app into an instant app

有人要求我在我正在开发的基础应用程序中制作一个可从 Play 商店打开的即时应用程序模块。

基本应用程序很大,有很多活动。它还使用比免安装应用程序允许的权限更多的权限。

我是否可以仅从其中一个仅使用允许权限的活动中制作即时应用程序模块?

如果是,我应该怎么做?

换句话说,即使基本应用程序使用更多权限,我是否可以在免安装应用程序模块 (instant/AndroidManifest.xml) 的清单文件中声明允许的权限?

我问这个问题是因为 official documentation 没有提到在 instant/AndroidManifest.xml

中声明权限的方法

In other words, can I declare the allowed permissions in the manifest file of the instant app module (instant/AndroidManifest.xml) even though the base app uses many more permissions?

是的,您可以声明仅存在于您的 com.android.feature 模块中的权限。它与您的主清单中的操作没有什么不同,请参阅 googlesamples/android-instant-apps/analytics/feature/AndroidManifest.xml

中的示例

注意:如果此功能也是应用程序模块 gradle 中通过 implementation project(':feature') 安装的应用程序的一部分,则其清单内容将被合并,包括权限,因此您无需复制这些权限。

但随着您的权限在即时应用和安装应用之间多样化,您可能 运行 到 errors that you'll have to watch out for. Just make sure that your permissions, uses-feature, and uses-implied-feature (ie Play filters) 在它们之间同步,以便安装应用的可定位设备不会比您的即时应用窄应用