android - 检测定位的 "Bluetooth scanning"是否开启

标签 android bluetooth bluetooth-lowenergy android-bluetooth android-location

从 Android M 开始,如果您在位置设置中启用了蓝牙扫描选项(请参见屏幕截图),即使关闭了全局定位功能,也可以在后台扫描蓝牙设备。

为了扫描 BLE 设备,必须满足以下条件:

    已授予
  • COARSE_LOCATIONFINE_LOCATION 权限。

以及以下之一:

  • 已启用全局位置选择器。
  • 蓝牙扫描选项已启用(见屏幕截图)。

我可以检查权限是否已授予,位置选择器的状态是否正常。我无法做的是弄清楚如何检查蓝牙扫描选项的状态?

非常感谢任何见解!

Marshmallow Bluetooth Scanning Option

最佳答案

经过大量的查找,终于找到了一种了解状态的方法:

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 扫描状态。 它不需要任何权限。

如果我找到将用户重定向到屏幕或禁用它的方法,我将更新这篇文章。

关于android - 检测定位的 "Bluetooth scanning"是否开启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39004377/

相关文章:

使用 D-Bus (qdbus) Send With org.bluez.MediaTransport1 发送 AVRCP 音量更改的蓝牙问题

android - 使用 Intent.ACTION_SEND_MULTIPLE 通过蓝牙发送多个文件

java - 致命异常: main unable to start activity android

Android 实例化一个虚拟的 PendingIntent

安卓蓝牙打印机连接

android - 我们如何检测具有 BLE 广告功能的 Android 手机

bluetooth-lowenergy - BlueGiga BLE113 和 Nordic Semiconductors nRF51822 有什么区别

Android BLE 广告失败,错误代码为 1

c# - Xamarin 工作室 "Error XA5209: Unzipping failed. Please download"

java - NullPointerException (@PhoneWindow :onKeyUpPanel:1002) {main}