How to know an application is installed from googl

2019-01-03 02:07发布

I need to detect my application is installed from google play or other market, how could I get this information?

3条回答
孤傲高冷的网名
2楼-- · 2019-01-03 02:17

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;
}
查看更多
Fickle 薄情
3楼-- · 2019-01-03 02:19

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".

查看更多
家丑人穷心不美
4楼-- · 2019-01-03 02:28

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.

查看更多
登录 后发表回答