gpt4 book ai didi

android - 使用 Android 应用程序找不到蓝牙服务

转载 作者:行者123 更新时间:2023-11-30 16:58:33 25 4
gpt4 key购买 nike

启动用 c 编写的蓝牙服务器后。

https://github.com/RyanGlScott/BluetoothTest/blob/master/C%20BlueZ%20Server/bluez_server.c

这是命令 sdptool browser 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 browser local 可以看到它?

这是 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。有人可以解释一下为什么吗?

最佳答案

bluetoothDevice.getUuids();

此方法不会启动服务发现过程来从远程设备检索 UUID。相反,会返回服务 UUID 的本地缓存副本。

改用fetchUuidsWithSdp()。此方法在远程设备上执行服务发现以获得支持的 UUID。

关于android - 使用 Android 应用程序找不到蓝牙服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38716543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com