就像在运行BuildConfig.FLAVOR
时BuildConfig.DEBUG
是否有构建标志来检查 APK 版本或 Android 应用程序的 Instant App 版本?
还是有其他获取信息的方法?
就像在运行BuildConfig.FLAVOR
时BuildConfig.DEBUG
是否有构建标志来检查 APK 版本或 Android 应用程序的 Instant App 版本?
还是有其他获取信息的方法?
build.gradle
将依赖项添加到模块中:implementation 'com.google.android.instantapps:instantapps:1.0.0'
然后您将能够使用该功能InstantApps.isInstantApp(this)
。
请注意,您必须通过更改项目中的存储库来使用 Maven Google build.gradle
:
buildscript {
repositories {
maven {
url 'https://maven.google.com'
}
jcenter()
}
...
}
allprojects {
repositories {
maven {
url 'https://maven.google.com'
}
jcenter()
}
}
最简单的方法是使用PackageManager.isInstantApp()
:
或者,常规(非 appcompat 版本)https://developer.android.com/reference/android/content/pm/PackageManager#isInstantApp()
还有一个覆盖,它接受包名称作为字符串,如果权限允许,它允许检查其他应用程序。
是的,您可以确定当前应用程序是已安装应用程序还是即时应用程序。首先在您的功能模块 build.gradle 中添加依赖项
api "com.google.android.instantapps:instantapps:1.0.0"
将您的项目级别 build.gradle 与此匹配
buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}...
}
allprojects {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
}
最后在运行时你可以写
if (InstantApps.isInstantApp(this)) {
// Do something like, show install button
} else {
// Do something like, hide install button
}