Is it possible to get the source of install from an Android app?

I mean, I want to see, if the app is installed from the Play Store, Amazon Appstore or via executing an APK.

PS: I think to see it while my app crashes and I was able to send an bug report, that my app was installed via Play Store. How do I get this value?

有帮助吗?

解决方案

The PackageManager class supplies the getInstallerPackageName method that will tell you the package name of whatever installed the package you specify. Side-loaded apps will not contain a value.

The latest version of the Amazon store finally sets PackageManager.getInstallerPackageName() to "com.amazon.venezia" as well to contrast with Google Play's "com.android.vending".

Source: How to know an application is installed from google play or side-load? For an Example: getInstallerPackageName returns null

其他提示

At present (16/01/2022) code:

val s = applicationContext.getPackageManager().getInstallerPackageName(applicationContext.getPackageName())

works fine for Android 11 in GooglePlay, and get "com.android.vending".

Use getInstallerPackageName.

This stores the packageName of what installed the application.

  • Google Play: "com.android.vending"
  • Amazon Appstore: "com.amazon.venezia"

Here's a util function (in Kotlin) that you can add to your code:

/**
 * Retrieves the name of the app responsible for the installation of this app.
 * This can help in identifying which market this app was installed from or whether the user
 * sideloaded it using an APK (Package Installer).
 */
fun getAppInstaller(context: Context): String {
    val appContext = context.applicationContext

    val installerPackageName = try {
        val appPackageManager = appContext.packageManager
        val appPackageName = appContext.packageName

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
            appPackageManager.getInstallSourceInfo(appPackageName).installingPackageName
        else
            appPackageManager.getInstallerPackageName(appPackageName)
    } catch (e: Exception) {
        e.printStackTrace()
        "--"
    }

    return when (installerPackageName) {
        "com.android.vending" -> "Google Play Store"
        "com.amazon.venezia" -> "Amazon AppStore"
        "com.huawei.appmarket" -> "Huawei AppGallery"
        "com.google.android.packageinstaller" -> "Package Installer"
        else -> installerPackageName ?: "Unknown"
    }
}

I used the answers of the great folks here in this StackOverflow question and others to create the above function. You can call this function passing it a context and then maybe set the return as a custom key in Crashlytics or record it for analytics or whatever you want.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top