【问题标题】:Can an Android app only allow itself to be installed on devices with a magnetic sensor?Android 应用程序只能安装在带有磁传感器的设备上吗?
【发布时间】:2017-11-08 08:53:34
【问题描述】:

Android 应用是否只能从 Google Play 安装到带有磁传感器(指南针)的设备上?

是否可以通过其他方式限制目标设备?

【问题讨论】:

  • <uses-feature 与磁性传感器一起使用,并将 required 设置为 true。它不会阻止安装,但会在 GOogle Play 中对不兼容的设备隐藏它。任何拥有 APK 的人仍然可以安装它

标签: android magnetometer


【解决方案1】:

将此添加到您的AndroidManifest.xml

<uses-feature
  android:name="android.hardware.sensor.compass"
  android:required="true" />

查看更多详情here

正如@Zoe 提到的,如果有人拥有 APK,它将隐藏在 Play 商店中,但不会阻止安装。如果您想阻止应用程序的使用,那么您可以在您的启动活动中添加一个检查并阻止用户使用任何功能。

PackageManager mgr = getPackageManager();
boolean hasCompass = mgr.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    相关资源
    最近更新 更多