android BluetoothDevice.getName() return null

前端 未结 7 575
没有蜡笔的小新
没有蜡笔的小新 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:19

    For someone hasn't found the solution.

    1. Bluetooth advertisement package has maximum size is 31 bytes. So if your device has long name. It can be truncated. See: https://devzone.nordicsemi.com/f/nordic-q-a/14/what-s-the-maximum-size-for-an-advertisement-package

    2. If you do want to get correct name of bluetooth device (even long name), please don't use startLeScan(). Instead of it, using method startDiscovery(). Google said: "The discovery process usually involves an inquiry scan of about 12 seconds, followed by a page scan of each device found to retrieve its Bluetooth name.". I've tried and it works like a charm. See: https://developer.android.com/guide/topics/connectivity/bluetooth

    0 讨论(0)
提交回复
热议问题