[英]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.