android如何检查应用程序是从(Play商店/ Android市场)或(蓝牙/其他)下载

时间:2013-10-11 08:53:32

标签: android bluetooth

我想在我的应用程序ABCD上验证。我在我的应用程序中添加了功能,将其发送到其他设备。我可以通过蓝牙将我安装的应用程序ABCD从我的设备发送到其他设备。 现在,我想创建支票。

if(isFromPlayStore){
    // always valid downloaded from play store
}else{
    // trial version expired in 30 day
} 

2 个答案:

答案 0 :(得分:1)

请查看here。这可能有助于您获得一些想法。

答案 1 :(得分:0)

普通用户下载应用程序有两种最常用的方式。

" com.android.vending" 是Google Play商店,

" com.amazon.venezia" 是亚马逊应用商店,

" null" 当它被侧载时(未知来源)

要检查此项,请使用以下代码:

final PackageManager packageManager = getPackageManager();

try {
    final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0);
    if ("com.android.vending".equals(packageManager.getInstallerPackageName(applicationInfo.packageName))) {
        // App was installed by Play Store
    }  else if ("com.amazon.venezia".equals(packageManager.getInstallerPackageName(applicationInfo.packageName))) {
        // App was installed by Amazon Appstore
    } else {
        // App was installed from somewhere else
    }
} catch (final NameNotFoundException e) {
    e.printStackTrace();
}