由于我目前正在为Android的一点点蓝牙库,我试图让我发现在我的周围设备的所有服务的UUID。
As I'm currently working on a little bluetooth library for Android, I'm trying to get all the service uuids of the devices I discovered in my surrounding.
在我的广播接收器获取 BluetoothDevice.ACTION_FOUND
的意图,我提取设备和呼叫:
When my broadcast receiver gets the BluetoothDevice.ACTION_FOUND
intent, I'm extracting the device and call:
device.fetchUuidsWithSdp();
这将导致 BluetoothDevice.ACTION_UUID
意图为每个设备发现,我处理它们使用相同的接收器:
This will result BluetoothDevice.ACTION_UUID
intents for each device found and I'm handling them with the same receiver:
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?
How can i get all the UUIDs of the surrounding devices?
编辑:
进出口工作在一台Nexus 7。我试过$ C $词在互联网上找到,这也给了我一个NullPointerException异常:http://digitalhacksblog.blogspot.de/2012/05/android-example-bluetooth-discover-and.html
Im working on a Nexus 7. I tried code i found on the internet and this also gives me a NullPointerException: http://digitalhacksblog.blogspot.de/2012/05/android-example-bluetooth-discover-and.html
感谢你。
的documentation在这个国家......
The documentation on this states...
总是包含额外的字段 BluetoothDevice.EXTRA_UUID
不过,就像你一样,我发现这是不正确的。
However, just like you, I have found this not to be true.
如果你调用 fetchUuidsWithSdp()
,而设备发现仍在进行 BluetoothDevice.EXTRA_UUID
可以为空。
If you call fetchUuidsWithSdp()
while device discovery is still taking place BluetoothDevice.EXTRA_UUID
can be null.
您应该等待,直到收到 BluetoothAdapter.ACTION_DISCOVERY_FINISHED
您拨打任何电话,以前fetchUuidsWithSdp()
。
You should wait until you receive BluetoothAdapter.ACTION_DISCOVERY_FINISHED
before you make any calls to fetchUuidsWithSdp()
.