有没有一个Android构建标志可以检查应用程序的APK版本和即时应用程序版本?

9

就像BuildConfig.FLAVORBuildConfig.DEBUG一样,是否有一个构建标志可以在运行时检查Android应用程序的APK版本或即时应用程序版本?

或者是否有其他获取信息的方式?

3个回答

13
在模块的build.gradle中添加依赖:implementation 'com.google.android.instantapps:instantapps:1.0.0',然后您就可以使用函数InstantApps.isInstantApp(this)
请注意,在项目的build.gradle中更改存储库时,您必须使用Maven Google。
buildscript {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
    ...
}

allprojects {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
}

Android即时应用API参考


3

该方法仅存在于API级别26+;但这将是正确的方式。 - FireZenk
我找到了这个方法,但现在它在一个不同的对象InstantApps.isInstantApp(context),谢谢你的情报。 - undefined

1

是的,您可以确定当前应用程序是已安装的应用程序还是即时应用程序。首先,在您的功能模块 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
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接