+-

由于我目前正在为 Android安装一个小蓝牙库,我正试图获得我在周围发现的设备的所有服务uuids.
当我的广播接收器获得BluetoothDevice.ACTION_FOUND意图时,我正在提取设备并调用:
device.fetchUuidsWithSdp();
这将导致找到的每个设备的BluetoothDevice.ACTION_UUID意图,并且我使用相同的接收器处理它们:
BluetoothDevice d = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Parcelable[] uuidExtra = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);
if(uuidExtra == null) {
Log.e(TAG, "UUID = null");
}
if(d != null && uuidExtra != null)
Log.d(TAG, d.getName() + ": " + uuidExtra.toString());
问题是,uuidExtra总是为空.
我怎样才能获得周围设备的所有UUID?
编辑:
我在Nexus 7上工作.我尝试在互联网上找到的代码,这也给了我一个NullPointerException:http://digitalhacksblog.blogspot.de/2012/05/android-example-bluetooth-discover-and.html
谢谢.
最佳答案
关于这个状态的 documentation ……
Always contains the extra field
BluetoothDevice.EXTRA_UUID
然而,就像你一样,我发现这不是真的.
如果在设备发现仍在进行时调用fetchUuidsWithSdp(),则BluetoothDevice.EXTRA_UUID可以为null.
在对fetchUuidsWithSdp()进行任何调用之前,您应该等到收到BluetoothAdapter.ACTION_DISCOVERY_FINISHED.
点击查看更多相关文章
转载注明原文:Android蓝牙:获取已发现设备的UUID - 乐贴网