【问题标题】:How to change the name of bluetooth low energy device in Android 4.3?如何在 Android 4.3 中更改蓝牙低功耗设备的名称?
【发布时间】:2013-11-19 05:48:29
【问题描述】:

我正在开发一个应用程序,我必须连接到 Android 4.3 上的蓝牙设备。

我想通过 Android 应用程序更改 CC2541 Keyfob 的名称。

我尝试使用 0x2A00 来获取设备名称服务,但是当我调用 Device_Name 函数时它发现它不起作用。

Name_Service 为空。

 private static final UUID Device_Name_UUID = UUID.fromString("00002a00-0000-1000-8000-00805f9b34fb");
private static final UUID Write_UUID = UUID.fromString("00001800-0000-1000-8000-00805f9b34fb");



    public void Device_Name(){
        BluetoothGattService Name_Service = mBluetoothGatt.getService(Write_UUID );
        if(Name_Service == null) {
            Log.d(TAG, "Name_Service service not found!");
            return;
        }

        BluetoothGattCharacteristic DeviceName = Name_Service.getCharacteristic(Device_Name_UUID);
        if(DeviceName == null) {
            Log.d(TAG, "DeviceName charateristic not found!");
            return;
        }

    }


Log.v(TAG, "readCharacteristic(DeviceName) = " + mBluetoothGatt.readCharacteristic(DeviceName));

String i = "123";       
DeviceName.setValue(i);
Log.v(TAG, "writeCharacteristic(DeviceName) = " + mBluetoothGatt.writeCharacteristic(DeviceName));

我可以从 BLE 设备读取名称,但是当我使用 mBluetoothGatt.readCharacteristic(DeviceName) 时它显示 writeCharacteristic(DeviceName) 为 false。

是否有人尝试使用设备名称的 UUID(0x2A00) 将名称写入 BLE 设备??

【问题讨论】:

  • 您发现这些服务了吗?顺便说一句,变量的命名约定令人困惑。尽量不要在变量名的第一个字母中使用大写字母,因为这通常表示类而不是 java 中的变量。
  • @reTs:我修改了代码。我可以从 ble 设备中获取服务并读取名称,但是当我使用 writeCharacteristic 时它是错误的。

标签: android bluetooth bluetooth-lowenergy android-bluetooth android-4.3-jelly-bean


【解决方案1】:

您需要修改CC2541 keyfob的固件,添加设备名称的写入权限,方法是在keyfobdemo.c中的KeyFobApp_Init()中添加如下代码:

uint8 devNamePermission = GATT_PERMIT_READ|GATT_PERMIT_WRITE; 
GGS_SetParameter( GGS_W_PERMIT_DEVICE_NAME_ATT, sizeof ( uint8 ), &devNamePermission );

参考:http://processors.wiki.ti.com/index.php/CC2540_DeviceNameWrite

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 2013-07-26
    • 2016-01-06
    • 2016-09-06
    • 2016-01-11
    • 1970-01-01
    • 2015-06-25
    相关资源
    最近更新 更多