需要为 Android 6.0 上的低功耗蓝牙扫描启用定位 [英] Location needs to be enabled for Bluetooth Low Energy Scanning on Android 6.0

查看:42
本文介绍了需要为 Android 6.0 上的低功耗蓝牙扫描启用定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到 Android 6.0 版后,蓝牙低功耗 (BLE) 扫描仅在设备上启用定位服务时才有效.请参阅此处参考:Android 6.0 上的蓝牙低功耗 startScan 找不到设备

After upgrading to Android version 6.0 Bluetooth Low Energy (BLE) scanning will only work if Location services are enabled on the device. See here for reference: Bluetooth Low Energy startScan on Android 6.0 does not find devices

基本上,您需要为应用程序以及手机启用权限.这是一个错误吗?是否可以在不实际启用定位服务的情况下进行扫描?我不想为我的所有应用程序提供位置信息.

Basically, you need to have the permission enabled for the app as well as on for the phone. Is this a bug? Is it possible to scan without location services actually enabled? I don't want to have to have location for all my apps.

编辑我没有提到我在 API 21 中提供的 BluetoothLeScanner 中使用了 startScan() 方法.我对这个方法的清单中的课程和精细位置权限没问题要求.我只是不希望我的应用程序的用户必须在他们的设备(GPS 等)上启用位置服务才能使用我的应用程序.

EDIT I failed to mention that I am using the startScan() method in BluetoothLeScanner provided in API 21. I am okay with the course and fine location permissions in the manifest that this method require. I just don't want the users of my app to have to enable location services on their device (GPS, etc.) to use my app.

以前,startScan() 方法会在手机上禁用定位服务的情况下运行并返回结果.然而,在 Marshmallow 上,当手机上未启用定位服务且路线/精细定位权限仍在清单中时,相同的应用程序会扫描"但无声地失败并且不返回任何结果.

Previously, the startScan() method would run and return results with the Location services disabled on the phone. On Marshmallow, however, the same application would "scan" but silently failed and returned no results when location services were not enabled on the phone and course/fine location permissions were still in the manifest.

推荐答案

不,这不是错误.

这个问题被提交给谷歌,他们回应说这是预期的行为,他们不会修复它.他们指示开发者访问这个网站 它指出硬件标识符访问现在需要位置许可.现在,开发者有责任让用户了解要求.

This issue was brought up to Google where they responded saying that this was the intended behavior and they won't fix it. They directed developers to this site where it points out that location permission is now needed for hardware identifier access. It is now the developer's responsibility to make their users aware of the requirement.

然而,在这个问题中,它没有解决为什么需要定位服务(GPS 等),而且他们似乎不会重新审视这个问题来解释这一点,因为它已被标记为预期行为.

In the issue, however, it doesn't address why Location services (GPS, etc.) are required and it doesn't seem like they are going to revisit the issue to explain this since it has been marked as the intended behavior.

回答问题的第二部分:是的,可以在不启用定位服务的情况下进行扫描.您可以使用 BluetoothAdapter.getDefaultAdapter().startDiscovery() 进行蓝牙经典扫描,这将在位置服务关闭的情况下工作.这将发现所有蓝牙设备、BLE 等.但是,如果 BLE 设备被视为 startScan() 的结果,它们将不会拥有扫描记录.

To answer the second part of the question: Yes, it is possible to scan without enabling Location services. You can do a Bluetooth classic scan using BluetoothAdapter.getDefaultAdapter().startDiscovery() and that will work with Location services off. This will discover all Bluetooth devices, BLE and otherwise. However, BLE devices won't have a scan record that they would have had if they were seen as a result of startScan().

这篇关于需要为 Android 6.0 上的低功耗蓝牙扫描启用定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆