我尝试在我的应用程序中实现动态功能模块。我在活动中有按钮。当用户单击我检查模块是否已安装。如果不是,我使用 startInstall(request) 开始安装。但我总是去其他州。
代码
if (manager.installedModules.contains("sample")) {
-----> Always go to this block
Toast.makeText(this, "Already Downloaded", Toast.LENGTH_SHORT).show()
Intent().setClassName(packageName, "com.example.sample.SampleActivity")
.also {
startActivity(it)
}
} else {
// Never came to this state
// Create request to install a feature module by name.
val request = SplitInstallRequest.newBuilder()
.addModule("sample")
.build()
// Load and install the requested feature module.
manager.startInstall(request)
}
在我设置的动态功能模块中onDemand="true"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.example.sample">
<dist:module
dist:onDemand="true"
dist:title="@string/title_sample">
<dist:fusing dist:include="true" />
</dist:module>
<application>
<activity android:name="com.example.sample.SampleActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
</application>