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

后端 未结 4 1298
野的像风
野的像风 2020-12-02 23:47

I plan on publishing my app on Amazon app store as well as Google Play, and have some things in my app that need to behave slightly different depending on whether the app wa

4条回答
  •  囚心锁ツ
    2020-12-03 00:29

    Since samsung has not implemented the PackageManager.getInstallerPackageName(), it still returns null. So use the PackageManager.getInstalledPackages() to get all the packages and search for the samsungapp packagename "com.sec.android.app.samsungapps".

    Stores:

    null - developer
    com.android.vending - google play
    com.amazon.venezia - amazon app
    com.sec.android.app.samsungapps - samsung app store
    

    Code:

    // lets start with google play store link
    String link = "https://play.google.com/store/apps/details?id=com.hellothupten.capital2countryquiz";
    
    //find out the installer for your app package name.
    String installer = getPackageManager().getInstallerPackageName(
            "com.hellothupten.capital2countryquiz");
    
    if (installer == null) {
        List installedPackages = getPackageManager()
                .getInstalledPackages(PackageManager.GET_ACTIVITIES);
        for (PackageInfo p : installedPackages) {
            if (p.packageName.contains("samsungapps")) {
                // change to samsung app store link
                link = "http://apps.samsung.com/mars/topApps/topAppsDetail.as?productId=000000840239";
                break;
            }
        }
    } else if (installer.contains("amazon")) {
        // change to amazon app store link
        link = "amzn://apps/android?p=com.hellothupten.capital2countryquiz";
    } else if (installer.contains("samsung")) {
        // change to samsung app store link. This does not
        // exist..but who knows samsung may implement
        // getInstallerPackageName in future, I assume it will
        // contain a word samsung in its package name.
        link = "http://apps.samsung.com/mars/topApps/topAppsDetail.as?productId=000000840239";
    
    }
    

    Use the link variable as the store link.

    Update:

    samsungapps://ProductDetail/com.sec.chaton
    

    Samsung: http://developer.samsung.com/android/technical-docs/Samsung-Apps-Deeplink-Guide

提交回复
热议问题