6

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.

starball
  • 20,030
  • 7
  • 43
  • 238
James
  • 263
  • 3
  • 6
  • 1
    Your answer is probably going to vary by library. And, few people will be proficient in all of these. Please provide links, or, better yet, explain how you use each of them (e.g., ``?). – CommonsWare Jan 06 '13 at 00:42
  • You could use a `public static final boolean` variable for each API, then check its value when referencing it. I think that's about the best one-size-fits-all solution you'll find; as CommonsWare said, other solutions will be API-specific. – Cat Jan 06 '13 at 00:54
  • For the Amazon Payments API at least, I know it enters sandbox mode if it can't connect – Jason Robinson Jan 06 '13 at 01:03

1 Answers1

5

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.

Robin Davies
  • 7,547
  • 1
  • 35
  • 50