Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 317
James Avatar asked Jan 06 '13 00:01

James


People also ask

What is hidden API?

Android Hidden APIs are classes, methods and resources that Google hides from you because of stability reason. These features are hidden because they may be changed on next API version. The internal APIs are located in package com.

Which API is best for Android development?

BBVA API Market BBVA's open API platform also offers many possibilities. The BBVA Customers API, for example, allows applications for Android and other systems to use an OAuth-based interface to handle information belonging to BBVA users and customers.

What is API integration in Android?

API integration is a connection between two or more applications, via their APIs, that lets those systems exchange data between each other. Today, in our app-connected world, API integration is critical to all organizations.


1 Answers

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.

like image 140
Robin Davies Avatar answered Oct 05 '22 13:10

Robin Davies