Max
Max

Reputation: 6394

How android app can detect what store installed it?

I have app in Google Play, Amazon, Samsung Apps and I plan to upload to other stores. I do not wish to compile separate build for every store. Is there way to detect what store installed app if same app submitted to different stores?

Upvotes: 13

Views: 5841

Answers (4)

jacksonfdam
jacksonfdam

Reputation: 441

Hope it helps

fun handleAppStoreSpecificLogic(context: Context) {
    val packageManager = context.packageManager
    val installerPackageName = packageManager.getInstallerPackageName(context.packageName)

    when (installerPackageName) {
        "com.android.vending" -> {
            // Google Play Store
            doGooglePlayStoreThings()
        }
        "com.amazon.venezia" -> {
            // Amazon Appstore
            doAmazonAppstoreThings()
        }
        "com.sec.android.app.samsungapps" -> {
            // Samsung Galaxy Store
            doSamsungGalaxyStoreThings()
        }
        "com.huawei.appmarket" -> {
            // Huawei AppGallery
            doHuaweiAppGalleryThings()
        }
        "com.xiaomi.mipicks" -> {
            // Xiaomi Mi GetApps
            doXiaomiMiGetAppsThings()
        }
        "com.oppo.market" -> {
            // OPPO App Market
            doOppoAppMarketThings()
        }
        "com.vivo.appstore" -> {
            // VIVO App Store
            doVivoAppStoreThings()
        }
        "com.hihonor.appmarket" -> {
            // Honor App Market
            doHonorAppMarketThings()
        }
        else -> {
            // Unknown or direct installation
            doDefaultThings()
        }
    }
}

fun doGooglePlayStoreThings() {
    // Implement Google Play Store specific logic here
}

fun doAmazonAppstoreThings() {
    // Implement Amazon Appstore specific logic here
}

fun doSamsungGalaxyStoreThings() {
    // Implement Samsung Galaxy Store specific logic here
}

fun doHuaweiAppGalleryThings() {
    // Implement Huawei AppGallery specific logic here
}

fun doXiaomiMiGetAppsThings() {
    // Implement Xiaomi Mi GetApps specific logic here
}

fun doOppoAppMarketThings() {
    // Implement OPPO App Market specific logic here
}

fun doVivoAppStoreThings() {
    // Implement VIVO App Store specific logic here
}

fun doHonorAppMarketThings() {
    // Implement Honor App Market specific logic here
}

fun doDefaultThings() {
    // Implement default logic for unknown or direct installations
}

Upvotes: 0

prestomation
prestomation

Reputation: 7440

You'll have to expand this for each additional store, but this should get you started

if (context.getPackageManager().getInstallerPackageName(context.getPackageName()).equals("com.android.vending")
{
//do google things
}
else if (context.getPackageManager().getInstallerPackageName(context.getPackageName()).equals("com.amazon.venezia")
{
//do amazon things
}

Upvotes: 16

donfuxx
donfuxx

Reputation: 11313

I detect Installer like this inside the MainActivity:

//is installed via amazon, google?
String installerId = null;
try {
    installerId = this.getPackageManager().getInstallerPackageName(this.getPackageName());
} catch (Exception e) {
    //just in case...
}

if ("com.amazon.venezia".equals(installerId)) {
    // amazon 
} else if ("com.android.vending".equals(installerId)) {
    // google
} else {
    // others & unknown ones
}

I have tested this in my last app and it passed app submission in googe play, amazon store and slideme.org store

Update: looks like sometimes there is the installer package name com.google.android.feedback which seems to be related to google store as well, although I have seen in my test app's google analytics that com.android.vending is by far more frequent. So if you want to make this even more precise you should handle this installer package as well. Also note that some markets (like slideme.org) simply don't seem to set a package installer id at all.

See also: Can PackageManager.getInstallerPackageName() tell me that my app was installed from Amazon app store?

Upvotes: 11

Warpzit
Warpzit

Reputation: 28152

Not unless you make seperate builds. But with a good maven setup/ant script you could easely automate this process.

Upvotes: 3

Related Questions