我是
Android的新手,现在正在做一个简单的应用程序,需要将一些数据写入外围设备.
三星GT-S7272C设备其实没有什么问题.但是当我切换到Sony LT29i时,当我试图写入某个特性时,总是会有一个状态133.我会给出一些简短的代码.
BluetoothGattService syncService = gatt.getService(SYNC_DATA_SERVICE);
BluetoothGattCharacteristic tChar = syncService.getCharacteristic(SYNC_TIME_INPUT_CHAR);
if (tChar == null) throw new AssertionError("characteristic null when sync time!");
int diff = /*a int*/;
tChar.setValue(diff,BluetoothGattCharacteristic.FORMAT_SINT32,0);
gatt.writeCharacteristic(tChar);
和onCharacteristicWrite函数:
@Override
public void onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status) {
Log.d(TAG,String.format("Sync: onCharWrite,status = %d",status));
try {
if (status != BluetoothGatt.GATT_SUCCESS) throw new AssertionError("Error on char write");
super.onCharacteristicWrite(gatt,characteristic,status);
if (characteristic.getUuid().equals(SYNC_TIME_INPUT_CHAR)) {
BluetoothGattService syncService = gatt.getService(SYNC_DATA_SERVICE);
BluetoothGattCharacteristic tChar = syncService.getCharacteristic(SYNC_HEIGHT_INPUT_CHAR);
if (tChar == null) throw new AssertionError("characteristic null when sync time!");
tChar.setValue(/*another int*/,0);
gatt.writeCharacteristic(tChar);
}
else if {
...
}
} catch (AssertionError e) {
...
}
写入第一个特征没有错,控制将达到onCharacteristicWrite,并输入状态为0的第一个if语句,这意味着成功.问题是在if语句中的第二个写入动作,它也将触发CharCharacteristicWrite函数,但产生状态133,在the official site中找不到,然后设备将自动断开.
我已经确认数据类型和偏移量都是正确的.并且因为在另一个设备中,它的工作非常好,我认为在不同的设备之间可能会有一些微小的蓝牙栈实现差异,我应该做更多的棘手来解决这个问题.
我搜索结果很长时间.一些结果导致我的C源代码(对不起,我会发布链接,因为我没有足够的声誉发布超过2个链接),但我只能发现133意味着GATT_ERROR在那里,这不是更有帮助而不仅仅是一个133.我还发现一个问题在谷歌集团,讨论一些熟悉的问题,但我没有找到一个解决方案在这里.
我有点伤心,因为如果C代码有问题,即使我可以找到错误的地方,我仍然没有办法在我自己的代码中正确使用它,对吗?
我希望有人有熟悉的经验,可能会给我一些建议.非常感谢!
> C源代码:https://android.googlesource.com/platform/external/bluetooth/bluedroid/ /android-4.4.2_r1/stack/include/gatt_api.h
>问题:https://code.google.com/p/android/issues/detail?id=58381