Add method to check which App Store the Android app is installed from, or if it’s sideloaded.

Andres Sandoval
1 min readMar 23, 2019
Spartan Sprint San Jose 2019. I completed my Spartan trifecta on March 17, 2019.

Java Code:

/**
* Get the name of App Store the App is installed from.
*/
public static String getAppStore(Context context) {
String pName = BuildConfig.APPLICATION_ID;

PackageManager packageManager = context.getPackageManager();
String installPM = packageManager.getInstallerPackageName(pName);
if ("com.android.vending".equals(installPM)) {
// Installed from the Google Play
return "Google Play";
} else if ("com.amazon.venezia".equals(installPM)) {
// Installed from the Amazon Appstore
return "Amazon Appstore";
}
return "unknown";
}

Debug in log

Log.d("myApp", "getAppStore: "+ Utils.getAppStore(this));

Kotlin code:

/**
* Get the name of App Store the App is installed from.
*/
fun getAppStore(context: Context): String {
val pName = BuildConfig.APPLICATION_ID

val packageManager = context.packageManager
val installPM = packageManager.getInstallerPackageName(pName)
if ("com.android.vending" == installPM) {
// Installed from the Google Play
return "Google Play"
} else if ("com.amazon.venezia" == installPM) {
// Installed from the Amazon Appstore
return "Amazon Appstore"
}
return "unknown"
}

Thanks for reading :)

--

--

Responses (1)