android - 检测是否从 Play 商店安装了应用

标签 android

我想检查并允许使用我的应用程序,只要它是从 Play 商店下载的,并且它没有被其他用户或任何其他来源共享。如果应用不是从 Google Play 商店下载的,我该如何阻止用户使用该应用?

最佳答案

此方法将检查您的应用是否已从 Play 商店安装。

boolean verifyInstallerId(Context context) {
    // A list with valid installers package name
    List<String> validInstallers = new ArrayList<>(Arrays.asList("com.android.vending", "com.google.android.feedback"));

    // The package name of the app that has installed your app
    final String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName());

    // true if your app has been downloaded from Play Store 
    return installer != null && validInstallers.contains(installer);
}

几天前我发布了一个 Android 库,PiracyChecker ,它使用一些技术保护您的应用程序,例如 Google Play 许可 (LVL)、APK 签名保护和安装程序 ID(这一项)。

关于android - 检测是否从 Play 商店安装了应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37539949/

相关文章:

android - 如何将数据从 fragment 发送到 Activity

android - 缺少 Google Awareness API v9.6

java - 以非常高的速度从服务向 Activity 发送连续数据

android - 将图像从 RecyclerView 转换为位图

Android Gmail 无法正确缩放背景图片

android - 我在哪里可以学习如何实现 'Where is my water' 的物理原理?

安卓 : SharedPreferences in BroadcastReceiver RadioButton's integer value do not update?

java - 无法理解 IndexOutOfBoundsException

java - 将 ArrayList 转换为字符串数组

android - 使用 Camera2 API 在服务中拍照