启动用c。
编写的BLUETOOTH服务器https://github.com/RyanGlScott/BluetoothTest/blob/master/C%20BlueZ%20Server/bluez_server.c
这是命令sdptool browse local:
的输出....other services....
Service Name: AVRCP CT
Service RecHandle: 0x10005
Service Class ID List:
"AV Remote" (0x110e)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 23
"AVCTP" (0x0017)
uint16: 0x103
Profile Descriptor List:
"AV Remote" (0x110e)
Version: 0x0100
/*MY SERVICE!!!*/
Service Name: Armatus Bluetooth server
Service Description: A HERMIT server that interfaces with the Armatus Android app
Service Provider: Armatus
Service RecHandle: 0x10006
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 3
Profile Descriptor List:
"Serial Port" (0x1101)
Version: 0x0100
....other services....
我正在尝试使用Android应用程序找到此服务
// Create a BroadcastReceiver for ACTION_FOUND
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// Whenever a remote Bluetooth device is found
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice bluetoothDevice =
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
adapter.add(bluetoothDevice.getName() + "\n"
+ bluetoothDevice.getAddress());
if (bluetoothDevice.getName().equals("mint-0")) {
Log.d("tagmint0","bene bene");
try {
ParcelUuid[] uuids = (ParcelUuid[]) bluetoothDevice.getUuids();
for (ParcelUuid uuid : uuids) {
Log.d("x", "mintUUIDxx: " + uuid.getUuid().toString() + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
};
我的问题是,为什么我的Android应用程序无法找到我的服务,即使使用命令sdptool浏览本地可以看到它?
这是android应用程序输出
mintUUIDxx: 0000111e-0000-1000-8000-00805f9b34fb
mintUUIDxx: 00001105-0000-1000-8000-00805f9b34fb
mintUUIDxx: 00001106-0000-1000-8000-00805f9b34fb
mintUUIDxx: 0000112d-0000-1000-8000-00805f9b34fb
mintUUIDxx: 0000110e-0000-1000-8000-00805f9b34fb
mintUUIDxx: 00001112-0000-1000-8000-00805f9b34fb
mintUUIDxx: 0000111f-0000-1000-8000-00805f9b34fb
mintUUIDxx: 00000000-0000-1000-8000-00805f9b34fb
正如您所看到的,它不包含服务器uuid。有人能解释我为什么吗?
答案 0 :(得分:0)
bluetoothDevice.getUuids();
此方法不会启动服务发现过程以从远程设备检索UUID。而是返回服务UUID的本地缓存副本。
请改用fetchUuidsWithSdp()
。此方法在远程设备上执行服务发现以获取支持的UUID。
答案 1 :(得分:0)
如果你使用了相同的git代码,那么看起来你在android中提到了不同的UUID。 在你bluez_server.c
uint32_t svc_uuid_int[] = { 0x01110000, 0x00100000, 0x80000080, 0xFB349B5F };
和android输出
mintUUIDxx: 0000111e-0000-1000-8000-00805f9b34fb
尝试使用此
更改bluez_server.c中的那一行uint32_t svc_uuid_int[] = { 0x0000111e, 0x00001000, 0x80000080, 0x5f9b34fb };