gpt4 book ai didi

android - mBluetoothGatt.getService(uuid) 返回 null

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:37:41 27 4
gpt4 key购买 nike

在我的应用程序中,我传递助听器服务的 UUID 编号,如来自谷歌的 BLE 示例,即 0000a00-0000-1000-8000-00805f9b34fb

但是 getservice 返回 null 意味着 BluetoothGatt 不支持该服务。为什么会这样,谁能帮帮我。

最佳答案

您必须首先根据文档发现给定设备的所有服务。

This function requires that service discovery has been completed for the given device. http://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#getService(java.util.UUID)

@Override
// New services discovered
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
BluetoothGattService mBluetoothGattService = mBluetoothGatt.getService(UUID.fromString(serviceUUID));
if (mBluetoothGattService != null) {
Log.i(TAG, "Service characteristic UUID found: " + mBluetoothGattService.getUuid().toString());
} else {
Log.i(TAG, "Service characteristic not found for UUID: " + serviceUUID);
}
}

或者你可以直接运行搜索

for (BluetoothGattService gattService : gattServices) {
Log.i(TAG, "Service UUID Found: " + gattService.getUuid().toString());
}

关于android - mBluetoothGatt.getService(uuid) 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19556096/

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