android - 如何在 Android 4.3 中更改蓝牙低功耗设备的名称?

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

我正在开发一个应用程序,我必须在 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 设备吗??

最佳答案

需要修改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

关于android - 如何在 Android 4.3 中更改蓝牙低功耗设备的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20064136/

相关文章:

android - 在首选项 Activity 中添加带有后退按钮的操作栏

android - SDK 管理器不显示示例包选项

java - 有可能当 inputStream.available != 0 时还没有收到完整的数据?

c# - 如何修复 GattStatus : 3 - WriteNotPermitted exception for BLE Xamarin forms application?

ios - 如何阻止系统警报并显示我的自定义屏幕

javascript - 不要让 WEbView 创建新选项卡

java - E/RecyclerView : No adapter attached; skipping layout. 尽管正在初始化适配器

android - 如何使用 BLE 将应用程序通知从一部 Android 手机传递到另一部 Android 手机

java - 将多个字符串组装成一个

ios - iBeacon可以检测配件的接近程度(背景中的应用程序)