是否有意打开wifi和蓝牙扫描意图要求用户提高位置准确度?
更新:我找到了一种更好的方式直接询问用户激活Wifi扫描这样做:
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiManager.isScanAlwaysAvailable()==false) {
startActivity(new Intent(WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE));
}
那么,我现在的问题是:我怎么能做同样的事情来请求扫描始终可用于蓝牙?我应该使用什么意图?
进入该屏幕的方法如下:
对于Nougat:打开Android设置,转到位置,右上角的3点菜单,扫描。
对于Oreo:打开Android设置,请转到安全和位置,位置,扫描
对于Pie:打开Android设置,转到位置,高级,扫描。
您可以使用LocationSettingsRequest提示用户启用位置。在请求中设置builder.setNeedBle(true);
以启用蓝牙扫描。
如果蓝牙已经打开,则不会要求用户启用蓝牙扫描。
连续扫描蓝牙会影响设备性能和电池寿命。因此,请您自担风险。
即使在Discovery完成后,下面的代码仍会检查设备。首先,确保使用注册接收器
IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(myReceiver, intentFilter);
并尝试运行代码。
private BluetoothAdapter mBtAdapter;
mBtAdapter.startDiscovery();
private final BroadcastReceiver mReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action))
{
//do something
}
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
{
Log.v(TAG,"Entered the Finished ");
mBtAdapter.startDiscovery();
}