我正在开发一个跟踪应用程序,我需要防止用户关闭用于确定位置的基本传感器。我无法修改设备 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 和蓝牙。您可以做的是如下实现或使用此库。
关于android - 如何防止用户关闭GPS、Wifi和蓝牙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56365092/