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

查看:200
本文介绍了需要在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()方法将在手机上禁用位置服务的情况下运行并返回结果.但是,在棉花糖上,当未在电话上启用位置服务并且清单中仍包含课程/精确位置权限时,同一应用程序将扫描"但无提示失败,并且不返回任何结果.

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.

推荐答案

不,这不是bug.

问题被带到Google,他们回答说这是预期的行为,他们不会修复它.他们指示开发人员访问此网站指出现在需要位置许可才能访问硬件标识符.现在,开发人员有责任让他们的用户意识到这一要求.

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和其他).但是,如果startScan()被视为BLE设备,则BLE设备将不会具有其扫描记录.

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天全站免登陆