您如何为 android 中的蓝牙服务命名?

how would you give name to bluetooth service in android things?

我在 android 中创建了一个简单的服务来使用蓝牙 BLE.when 我尝试使用 NRF connect 应用程序对其进行测试,它显示为 "unknown service"。我想给名字类似"Speed Service".我该怎么做?

private BluetoothAdapter bluetoothAdapter = null;
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

void ChangeDeviceName(){
                Log.i(LOG, "localdevicename : "+bluetoothAdapter.getName()+" localdeviceAddress : "+bluetoothAdapter.getAddress());
                bluetoothAdapter.setName("NewDeviceName");
                Log.i(LOG, "localdevicename : "+bluetoothAdapter.getName()+" localdeviceAddress : "+bluetoothAdapter.getAddress());
            }

参考:Change the Android bluetooth device name

希望这个案例与你相似,对你有用。

这是一个由您使用的扫描应用控制的因素,不一定是您的 Android Things 设备。 Bluetooth LE 不会通过无线方式发送 "service name" 之类的元数据。服务仅由其 UUID 标识。如果您的设备实现了 standard service UUIDs 之一,像 NRF Connect 这样的扫描仪应用程序将 可能 识别并显示服务类型。

作为另一个示例,我们的 Bluetooth GATT Server 示例通过使用蓝牙 SIG 为该服务采用的 UUID 来实现标准 当前时间服务