How to conditionally use vendor-specific APIs for Android apps?

后端 未结 1 1389
清歌不尽
清歌不尽 2021-01-02 23:50

With Android app stores offering marketplace-specific APIs, how do I build an Android app that conditionally uses vendor-specific libraries? For example, Amazon offers thei

相关标签:
1条回答
  • 2021-01-03 00:07

    I'm using this currently.

    private boolean isAmazonInstall()
    {
        PackageManager pm = getPackageManager();
        String installationSource = pm.getInstallerPackageName(getPackageName());
        if (installationSource != null && installationSource.startsWith("com.amazon"))
        {
                        return true;
        }
                return false;
    }
    

    Allegedly, for an Amazon install, the return value of getInstallerPackageName is "com.amazon.venezia". For applications installed from Google Play, the result is "com.android.vending" (although it used to be "com.google.android.feedback". Manual APK installs return null.

    I haven't been able to find official confirmation that this approach is valid. But I haven't been able to find any better approach.

    0 讨论(0)
提交回复
热议问题