BluetoothLeScanner.startScan with Android 6.0 does not discover devices

前端 未结 6 903
小蘑菇
小蘑菇 2020-12-30 21:53

I\'m trying to use the function BluatoothLeScanner.startScan instead of the deprecated one BluetoothAdapter.startLeScan. Yesterday I updated my Nexus 5 to

6条回答
  •  不知归路
    2020-12-30 22:24

    One - not perfect answer, is that you can still use the same old method BT scan method, once you have the new runtime Location permission enabled.

                mBluetoothAdapter.startDiscovery();
    

    .......

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
    
                    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                    BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    
                    mDeviceList.add(device);
    
    
                }
            }
        };
    

提交回复
热议问题