经过大量的搜索,我终于找到了一种了解状态的方法:
try {
ContentResolver resolver = getApplicationContext().getContentResolver();
int result = Settings.Global.getInt(resolver,"ble_scan_always_enabled");
if(result == 1) {
// Bluetooth scanning is on
} else {
// Bluetooth scanning is off
}
} catch(SettingNotFoundException e) {
// Settings doesn't exist, on Android < 6
}
您可以使用"wifi_scan_always_enabled"
来获取wifi扫描状态。它不需要任何权限。
如果我找到了重定向用户到屏幕或禁用它的方法,我会更新这篇文章。