簡體   English   中英

如何以編程方式在Android中更改連接的BLE設備名稱?

[英]How to change the connected BLE device name in Android programatically?

在我的Android應用程序中,一旦BLE設備連接到Android手機,BLE連接就能成功運行。 如何以編程方式更改連接的BLE設備名稱? 示例代碼如下

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));
        Log.v(TAG, "writeCharacteristic(DeviceName) = " + mBluetoothGatt.writeCharacteristic(DeviceName));

這里是mBluetoothGatt.writeCharacteristic(DeviceName); 方法總是返回false

經過一番研究后我找到了解決方案

您需要修改CC2541密鑰卡的固件,通過將以下代碼添加到keyfobdemo.c內的KeyFobApp_Init()中來添加設備名稱的寫入權限:

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

現在我的問題是,我們需要添加這些權限?

請任何人告訴我如何添加這些持久性?

提前致謝

正如名稱所示:keyfobdemo.c是一個.c文件,因此TI告訴您必須在KeyFobDemo工作區中添加這些權限,因此您必須對CC2541套件進行編程才能更改名稱。 你不能在Android中做到這一點。

你所要做的就是:

從德州儀器(TI)網站下載BLE堆棧: http//www.ti.com/tool/ble-stack

然后在堆棧中,打開Projects \\ ble \\ KeyFob \\ CC2541DB \\ KeyFobDemo.eww文件。

CC2540套件的編程需要一個名為IAR Embedded Workbench的IDE。 您可以下載它並通過30天的試用獲得訪問權限: http//www.iar.com/Products/IAR-Embedded-Workbench/8051/

然后打開項目並在APP文件夾中找到keyfobdemo.c文件。 從第200-213行開始,有一個名為deviceName []的char數組,它實際上將廣告名稱定義為“Keyfobdemo”。 您只需要使用正確的十六進制值以及數組的長度將其更改為所需的名稱。 然后在第236行中,您還必須更改attDeviceName []數組,因為此參數定義了設備處於連接狀態時的名稱。

在Android中無法做到這一點! 除非你改變你的BLE固件!

可能的解決方案是,一旦連接到BLE設備,就可以向設備發送一些配置命令來更改設備名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM