I need to detect my application is installed from google play or other market, how could I get this information?
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
回答1:
The PackageManager
class supplies the getInstallerPackageName method that will tell you the package name of whatever installed the package you specify. Side-loaded apps will not contain a value.
EDIT: Note @mttmllns' answer below regarding the Amazon app store.
回答2:
And FYI apparently the latest version of the Amazon store finally sets PackageManager.getInstallerPackageName()
to "com.amazon.venezia"
as well to contrast with Google Play's "com.android.vending"
.
回答3:
I use this code to check, if a build was downloaded from a store or sideloaded:
public static boolean isStoreVersion(Context context) {
boolean result = false;
try {
String installer = context.getPackageManager()
.getInstallerPackageName(context.getPackageName());
result = !TextUtils.isEmpty(installer);
} catch (Throwable e) {
}
return result;
}