如何有条件地使用供应商特定的API for Android应用程序? [英] How to conditionally use vendor-specific APIs for Android apps?

查看:149
本文介绍了如何有条件地使用供应商特定的API for Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用的Andr​​oid应用商店,提供市场上专用的API,如何构建一个Android应用程序,有条件地使用供应商特定的库?例如,亚马逊拥有自己的应用程序内购买和GameCircle的API。谷歌有自己的许可的API,而现在欧雅将有自己的API来IAP和硬件控制器。

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.

使用这些特定供应商的软件开发工具包它变得难以维持几个独立的泛滥建立了我的Andr​​oid游戏。我想知道如何建立我的项目,使我的code可以只检查在运行时的各种API和使用他们,如果avaialble。类似于

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.

推荐答案

我用这个当前。

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

据称,一个Amazon安装,getInstallerPackageName的返回值是com.amazon.venezia。对于来自谷歌安装的应用程序玩,结果​​被com.android.vending(虽然它使用的是com.google.android.feedback。手册APK安装返回null。

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.

这篇关于如何有条件地使用供应商特定的API for Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆