一光年lost 2016-08-11 03:30 采纳率: 57.1%
浏览 2665
已采纳

ble不能回调onCharacteristichanged方法

public void readManufacturer(){
    BluetoothGattService manufacturerService = mBluetoothGatt.getService(UUID.fromString(MANUFACTURER_SERVICE));
    if (manufacturerService != null) {
        //Log.d("demo", String.valueOf(manufacturerService.getCharacteristic(UUID.fromString(MANUFACTURER_CHARATERISTIC))));
        BluetoothGattCharacteristic manufacturerCharacteristic = manufacturerService.getCharacteristic(UUID.fromString(MANUFACTURER_CHARATERISTIC));
        Log.d("demo", String.valueOf(manufacturerCharacteristic));
        Log.d("demo", String.valueOf(manufacturerCharacteristic != null));
        if (manufacturerCharacteristic != null) {
            Log.d("demo","intoNotify");
            setCharacteristicNotification(manufacturerCharacteristic,true);
        }
    }
}


     public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,boolean enable){
    Log.d("demo", "setCharacteristicNotification");
    if(mBluetoothAdapter == null || mBluetoothGatt == null){
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(characteristic, enable);
    if(UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())){
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }
}

    打出来的Log:
    08-11 14:58:54.594 4768-4768/com.example.chongyanghu.mybletest D/demo: readBatteryAction

08-11 14:58:54.595 4768-4768/com.example.chongyanghu.mybletest D/demo: android.bluetooth.BluetoothGattCharacteristic@1893971
08-11 14:58:54.595 4768-4768/com.example.chongyanghu.mybletest D/demo: true
08-11 14:58:54.595 4768-4768/com.example.chongyanghu.mybletest D/demo: intoNotify
08-11 14:58:54.595 4768-4768/com.example.chongyanghu.mybletest D/demo: setCharacteristicNotification

进入了setCharacteristicNotification,为什么没有回调onCharacteristicChanged方法,求大牛帮忙看看~

  • 写回答

2条回答 默认 最新

  • 一光年lost 2016-08-11 07:31
    关注

    自己解决了
    public void readManufacturer() {
    BluetoothGattService manufacturerService = mBluetoothGatt.getService(UUID.fromString(MANUFACTURER_SERVICE));
    if (manufacturerService != null) {
    //Log.d("demo", String.valueOf(manufacturerService.getCharacteristic(UUID.fromString(MANUFACTURER_CHARATERISTIC))));
    BluetoothGattCharacteristic manufacturerCharacteristic = manufacturerService.getCharacteristic(UUID.fromString(MANUFACTURER_CHARATERISTIC));
    Log.d("demo", "manufacturerCharacteristic = " + String.valueOf(manufacturerCharacteristic != null));
    final int charaProp = manufacturerCharacteristic.getProperties();
    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
    Log.d("demo", "intoNotify--->" + String.valueOf((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0));
    readCharacteristic(manufacturerCharacteristic);
    }
    }
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)