android - 如何防止用户关闭GPS、Wifi和蓝牙?

标签 android android-sensors device-admin device-owner android-enterprise

我正在开发一个跟踪应用程序,我需要防止用户关闭用于确定位置的基本传感器。我无法修改设备 ROM 或拥有 root 访问权限(或者至少非常希望没有),但我想到了使用设备管理 API 通过 Profile Owner 或 Device Owner 模式执行这些功能。我基本上是在寻找一种在 Android 设置中阻止这些功能的方法。

我不确定这是否可行以及如何实现,我还没有在 GitHub 中找到实现此应用程序的示例。任何人都可以给我一个提示、一些示例或特定文档吗?

我尝试遵循这三个文档,但没有成功找到针对此特定功能的解决方案:

https://source.android.com/devices/tech/admin https://developer.android.com/guide/topics/admin/device-admin https://developers.google.com/android/management/introduction

这是我一直在尝试的摘录:

setUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, true);
setUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, active);
setUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH, active);

private void setUserRestriction(String restriction, boolean disallow){
    if (disallow) {
        mDevicePolicyManager.addUserRestriction(mAdminComponentName, restriction);
    } else {
        mDevicePolicyManager.clearUserRestriction(mAdminComponentName,
restriction);
    }
}

DISALLOW_CONFIG_BLUETOOTH Added in API level 18 public static final String DISALLOW_CONFIG_BLUETOOTH

Specifies if a user is disallowed from configuring bluetooth. This does not restrict the user from turning bluetooth on or off. The default value is false.

This restriction doesn't prevent the user from using bluetooth. For disallowing usage of bluetooth completely on the device, use DISALLOW_BLUETOOTH.

This restriction has no effect in a managed profile.

Key for user restrictions.

Type: Boolean

最佳答案

您无法阻止他们关闭 GPS、WIFI 和蓝牙。您可以做的是如下实现或使用此库。

https://github.com/KI-labs/gps-permission-checks-livedata

关于android - 如何防止用户关闭GPS、Wifi和蓝牙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56365092/

相关文章:

android - 当用户登录凭据存储在浏览器中时,Android 上的 Twitter OAuth 回调出现问题

java - OnSensorChanged 被调用的次数超过预期

Android获取四元数数据

android - "Enable Device Admin"对话框不显示

android - 手机重启时禁用设备管理员权限

android - 如何删除在 Android 上启用了 Activity 设备管理员的应用程序?

android - Android Studio 生成 Id 的最佳实践

android - 如何在 android 中将 Bitmap 转换为 Drawable?

android - 如何在没有GPS的情况下在android中获取用户的城市和国家?

android - 如何使用 JobScheduler 从后台应用程序获取步数