android BluetoothDevice.getName() return null

前端 未结 7 601
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 11:37

On sometime, BluetoothDevice.getName() return null. How can i fix it? remoteDeviceName maybe null in following code. And i need distinguish my device and other devices by re

7条回答
  •  温柔的废话
    2020-11-28 12:05

    On Marshmallow, utilize ScanRecord.getDeviceName() to retrieve the local name embedded in the scan record.

    BluetoothDevice.getName() is unreliable if the local name is included in a scan response, rather than in the immediate advertising packet.

        @Override
        public void onScanResult(int callbackType, ScanResult scanResult) {
            super.onScanResult(callbackType, scanResult);
    
            // Retrieve device name via ScanRecord.
            String deviceName = scanResult.getScanRecord().getDeviceName();
        }
    

提交回复
热议问题