是否有可能在运行时可靠地检测到安装了Android应用程序(Google Play或Amazon Market)的商店? [英] Is it possible to reliably detect at runtime which store installed an Android App (Google Play or Amazon Market)?

查看:421
本文介绍了是否有可能在运行时可靠地检测到安装了Android应用程序(Google Play或Amazon Market)的商店?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多类似的Stackoverflow问题。

所有的答案都建议在 PackageManager 上使用像 getInstallerPackageName $ c>类。

所有人都有评论或相互矛盾的答案,认为这不是一种可靠的方法,这表明可靠地检查哪个商店安装给定应用程序的唯一方法是生成两个单独的二进制文件,每个文件都有一个 storeFlag 集合,并将一个二进制文件上传到Amazon,另一个文件上传到Google Play。



我需要知道哪个商店是应用程序的安装程序,以便我知道哪个商店可以与应用程序内购买功能进行通信。



确定的 100%可靠性方法能够生成两个单独的二进制文件吗?或者是否存在基于代码的100%运行时方法?

最健壮的方法,但同时检查Build.MANUFACTURER和installerName应该让你非常接近(尽管假设你想检查亚马逊AppStore,如果用户已经在他们的非Kindle设备上安装了旧版本的安装程序并且未更新安装程序名可能报告为空)

  boolean isAmazonDevice = Build.MANUFACTURER.equalsIgnoreCase(amazon); 

final应用程序应用程序= getApplication();
String安装程序名= application.getPackageManager()。getInstallerPackageName(application.getPackageName());
boolean fromAmazonStore = installerName!= null&& installerName.equalsIgnoreCase( com.amazon.venezia);

然后检查以下值:

  isAmazonDevice || fromAmazonStore 

应该为您带来所需的大量时间。



这可能会混淆事件的一个场景是,如果您正在装载APK进行测试 - 在这种情况下,它将没有正确的InstallerPackageName。您可以使用以下方式装载apk来伪造:

  adb install -i com.amazon.venezia APK_NAME 

code>


There are many similar Stackoverflow questions.

All have answers that suggest using methods like getInstallerPackageName on the PackageManager class.

All also have comments or conflicting answers saying that this is not a reliable approach, suggesting that the only way to reliably check which store installed a given App is to generate two separate binaries, each with a storeFlag set, and upload one binary to Amazon and one to Google Play.

I need to know which store is the App's installer so that I know which store to communicate with for in-App purchase functionality.

Is the definitive 100% reliable approach to generate two separate binaries? Or is there a 100% reliable code-based runtime approach?

解决方案

two binaries would be the most robust method but checking both the Build.MANUFACTURER and the installerName should get you pretty close (though assuming yo want to check for the Amazon AppStore if the user has installed an old version of the installer on their non-Kindle device and not updated the installerName might report null)

boolean isAmazonDevice = Build.MANUFACTURER.equalsIgnoreCase("amazon");

final Application application = getApplication();
String installerName = application.getPackageManager().getInstallerPackageName(application.getPackageName());
boolean fromAmazonStore = installerName != null && installerName.equalsIgnoreCase("com.amazon.venezia");

and then checking the value for:

isAmazonDevice || fromAmazonStore

should get you what you need for a significant amount of the time.

One scenario where this can confuse matters is if you are sideloading your apk for testing - in that case it wouldn't have the correct InstallerPackageName. You can fake that by sideloading the apk using:

adb install -i com.amazon.venezia APK_NAME

这篇关于是否有可能在运行时可靠地检测到安装了Android应用程序(Google Play或Amazon Market)的商店?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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