![](/img/trans.png)
[英]Is it possible to reliably detect at runtime which store installed an Android App (Google Play or Amazon Market)?
[英]How to determine at runtime if app is installed via amazon appstore or Google play
如果通過Amazon Android Appstore或Google Play安裝了應用程序,建議在運行時確定最佳做法是什么? 我想避免為我的應用程序可用的每個appstore生成單獨的APK。
我首選的方法是使用PackageManger.getInstallerPackageName。
根據Android API文檔,這正是我正在尋找的:檢索安裝包的應用程序的包名稱。 這確定了包裹來自哪個市場。
不幸的是,通過Amazon Appstore(包括KF)安裝的應用程序似乎返回null,這是人們在用戶手動安裝APK時所期望的。
如果有另一種方法,有人可以告訴我。
除了返回null的問題之外, getInstallerPackageName()
可以被篡改並返回不准確的信息。
我已經研究了很長時間了,我能想出的最好的解決方案是有一個包含該信息的常量文件:
public class Constants {
public static final int GOOGLE_PLAY = 0;
public static final int AMAZON = 1;
public static final int BUILT_FOR = GOOGLE_PLAY;
}
只需在此文件中使用AMAZON
而不是GOOGLE_PLAY
,並為每個應用商店構建一次apk。
在代碼的其他地方,您可以使用以下方法檢查:
if(Constants.BUILT_FOR == Constants.GOOGLE_PLAY) {
//Google Play build
}
if(Constants.BUILT_FOR == Constants.AMAZON) {
//Amazon Build
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.