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

这一生的挚爱 提交于 2019-11-29 20:35:42

问题


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 their own In-App Purchase and "GameCircle" APIs. Google has their own Licensing APIs, and now Ouya will have their own APIs for IAP and hardware controllers.

With the proliferation of these vendor-specific SDKs it's becoming difficult to maintain several separate builds of my Android games. I would like to know how to build my projects so that my code can just check at runtime for various APIs and use them if avaialble. Something like

if (amazon api is available)
  // Do some amazon-specific stuff

At build-time I would link with ALL the libraries then upload the same universal app to each store.


回答1:


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.



来源:https://stackoverflow.com/questions/14178049/how-to-conditionally-use-vendor-specific-apis-for-android-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!