Is there an Android build flag to check for APK versus Instant App version of an App

坚强是说给别人听的谎言 提交于 2019-12-07 03:06:17

问题


Just like BuildConfig.FLAVOR and BuildConfig.DEBUG is there a build flag to check at runtime for the APK version or the Instant App version of an Android application ?

Or is there another way to get the information ?


回答1:


Add to the module build.gradle the dependency : implementation 'com.google.android.instantapps:instantapps:1.0.0' then you will be able to use the function InstantApps.isInstantApp(this).

Please note that you must use Maven Google by changing your repositories in the project build.gradle :

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

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

Android Instant Apps API reference




回答2:


Easiest way is to use PackageManager.isInstantApp() :

https://developers.google.com/android/reference/com/google/android/gms/instantapps/PackageManagerCompat.html#isInstantApp()

Or, a regular (non-appcompat version) https://developer.android.com/reference/android/content/pm/PackageManager#isInstantApp()

Also has an override which accepts package name as a string, which allows to check other apps, if permissions allow.




回答3:


Yes, You can determine whether the current app is Installed App or Instant app.First of all add the dependency in your feature module build.gradle

api "com.google.android.instantapps:instantapps:1.0.0"

Match you project level build.gradle with this

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

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

Finally at runtime you may write

if (InstantApps.isInstantApp(this)) {
        // Do something like, show install button
    } else {
        // Do something like, hide install button
    }


来源:https://stackoverflow.com/questions/44309515/is-there-an-android-build-flag-to-check-for-apk-versus-instant-app-version-of-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!