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
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();
}