在我的应用程序中,我传递了助听器服务的 UUID 编号,如 google 的 BLE 示例所示,即 0000a00-0000-1000-8000-00805f9b34fb
但是 getservice 返回 null 意味着该服务不受 BluetoothGatt 支持。
为什么会发生这种情况,任何人都可以帮助我。
您必须首先根据文档发现给定设备的所有服务。
此功能要求给定设备已完成服务发现。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());
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)