Android install source
Asked Answered
S

4

12

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?

Syzygy answered 24/4, 2014 at 7:51 Comment(0)
C
16

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

Calandracalandria answered 24/4, 2014 at 7:55 Comment(0)
T
3

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".

Teraterai answered 16/1, 2022 at 16:48 Comment(0)
A
3

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.

Alyse answered 11/10, 2022 at 23:1 Comment(0)
O
2

Use getInstallerPackageName.

This stores the packageName of what installed the application.

  • Google Play: "com.android.vending"
  • Amazon Appstore: "com.amazon.venezia"
Osmic answered 24/4, 2014 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.