Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:获取蓝牙SDP服务名称_Android_Bluetooth_Sdp - Fatal编程技术网

Android:获取蓝牙SDP服务名称

Android:获取蓝牙SDP服务名称,android,bluetooth,sdp,Android,Bluetooth,Sdp,Android Bluetooth API允许您使用以下方式注册SDP服务: String BLUETOOTH_NAME="MyBluetoothService"; mAdapter.listenUsingRfcommWithServiceRecord(BLUETOOTH_NAME, UUID.fromString(uuid)); 它还允许您在远程蓝牙设备上启动服务查找,以查找活动服务UUID的列表: device.fetchUuidsWithSdp(); 但是,似乎没有任何公共方法可用于获

Android Bluetooth API允许您使用以下方式注册SDP服务:

String BLUETOOTH_NAME="MyBluetoothService";
mAdapter.listenUsingRfcommWithServiceRecord(BLUETOOTH_NAME, UUID.fromString(uuid));
它还允许您在远程蓝牙设备上启动服务查找,以查找活动服务UUID的列表:

device.fetchUuidsWithSdp();

但是,似乎没有任何公共方法可用于获取服务名称。可以通过其他方式获取吗?

我想您希望获得设备上运行的服务的名称,就像在linux设备上一样

sdptool浏览本地| egrep“服务名称:”

所以答案是否定的,因为没有Android API方法,sdptool也不在Android上

但是,您可以使用NDK编写一个包含相应函数的c库,并通过JNI调用该函数(请参阅Bluetooth for Programmers的第一篇文章)


顺便问一下:为什么要按名称而不是UUID列出服务。根据我的经验,服务名称与实现略有不同,而UUID是可信的。

您好,谢谢您的回答。我想这样做是因为我想利用服务名称传递额外的信息(就像在常见的网络场景中使用TXT记录一样)