小编Sha*_*ale的帖子

BLuetooth Gatt Callback无法使用Lollipop的新API

我目前有一种方法可以写入BLE设备发出蜂鸣声.我的蓝牙回拨如下:

ReadCharacteristic rc = new ReadCharacteristic(context, ds.getMacAddress(), serviceUUID, UUID.fromString(myUUID), "") {
                @Override
                public void onRead() {
                    Log.w(TAG, "callDevice onRead");
                    try{Thread.sleep(1000);}catch(InterruptedException ex){}
                    WriteCharacteristic wc = new WriteCharacteristic(activity, context, getMacAddress(), serviceUUID, UUID.fromString(myUUID), ""){
                        @Override
                        public void onWrite(){
                            Log.w(TAG, "callDevice onWrite");
                        }
                        @Override
                        public void onError(){
                            Log.w(TAG, "callDevice onWrite-onError");
                        }
                    };

//                  Store data in writeBuffer
                    wc.writeCharacteristic(writeBuffer);
                }

                @Override
                public void onError(){
                    Log.w(TAG, "callDevice onRead-onError");
                }
            };

            rc.readCharacteristic();
Run Code Online (Sandbox Code Playgroud)

我的ReadCharacteristic实现如下:

public class ReadCharacteristic extends BluetoothGattCallback {
    public ReadCharacteristic(Context context, String macAddress, UUID service, UUID …
Run Code Online (Sandbox Code Playgroud)

android bluetooth-lowenergy android-bluetooth gatt android-5.0-lollipop

13
推荐指数
2
解决办法
1万
查看次数