检测“蓝牙扫描"是否存在.位置已开启

编程入门 行业动态 更新时间:2024-10-26 12:28:30
本文介绍了检测“蓝牙扫描"是否存在.位置已开启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

Since Android M it is possible to scan for Bluetooth devices in the background even if the global location is turned off if you have enabled the Bluetooth scanning option in location settings (see screenshot).

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

In order to scan for BLE devices, the following conditions must be met:

    授予
  • COARSE_LOCATION 或 FINE_LOCATION 权限.
  • COARSE_LOCATION or FINE_LOCATION permission granted.

以及以下之一:

  • 已启用全局位置选择器.
  • 启用了
  • 蓝牙扫描选项(请参见屏幕截图).
  • Global Location selector enabled.
  • Bluetooth scanning option enabled (see screenshot).

我可以检查是否已授予许可,并且位置选择器的状态也很好.我没办法做的是如何检查蓝牙扫描选项的状态?

I can check that the permission is granted and the state of the location selector just fine. What I haven't been able to do is figure out how to check the state of the Bluetooth Scanning option?

任何见解都将受到赞赏!

Any insights are much appreciated!

推荐答案

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

After a lot of search, I finally found a way to know the state:

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

You can also use "wifi_scan_always_enabled" to get wifi scanning state. It doesn't require any permissions.

如果我找到了一种将用户重定向到屏幕或禁用它的方法,我将更新此帖子.

I will update this post if I find a way to redirect the user to the screen or to disable it.

更多推荐

检测“蓝牙扫描"是否存在.位置已开启

本文发布于:2023-10-24 17:29:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:蓝牙   是否存在   位置   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!