微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

合并来自 BluetoothGattCallBack 的 RSSI 和特征值的结果

如何解决合并来自 BluetoothGattCallBack 的 RSSI 和特征值的结果

您好,

是否可以将 RSSi 值 (onReadRemote) 和特征值 (onCharateristicRead) 的结果合并到一个 broadcastUpdate 中?。我知道 RSSI 功能是在 API18 中添加的,但 Android 团队应该将其作为一个特性合并。

  @Override
      public void onReadRemoteRSSi(BluetoothGatt gatt,int status,int RSSi){
          if (status == BluetoothGatt.GATT_SUCCESS) {
              Log.d(TAG,String.format("BluetoothGatt ReadRSSi[%d]",RSSi));
              broadcastUpdate(ACTION_DATA_AVAILABLE,null,RSSi);
              mBluetoothGatt.readRemoteRSSi();
              try{                
              Thread.sleep(1000);
              }catch(InterruptedException e) {e.printstacktrace();}
              
           }
        }



  @Override
      public void onCharacteristicRead(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status) {
            if (status == BluetoothGatt.GATT_SUCCESS) {
            broadcastUpdate(ACTION_DATA_AVAILABLE,characteristic,status);
            }       

我无法同时广播 RSSi 和特征值。根据 debug/logcat,我看到 RSSi 被 onCharacteristicRead int 状态覆盖。有什么解决方法吗??

private void broadcastUpdate(final String action,final BluetoothGattCharacteristic characteristic,int RSSi) \\overwritten by int status value
                               {       
       final Intent intent = new Intent(action);
       int rdata = RSSi;
       if (UUID_HOOPRING_DATA.equals(characteristic.getUuid())) {
           final byte[] data =  characteristic.getValue();
           String Sdata = new String(data).replaceAll("\n","");
           String[] Fdata = new String(Sdata).split(",");
           int[] idata = new int[Fdata.length];
            for(int i=0; i < Fdata.length; i++)
               {
                idata[i] = Integer.parseInt(Fdata[i]);
               }    
            idata[1]=rdata;
            intent.putExtra(STATUS_DATA,idata);
            
      } 
       
        sendbroadcast(intent);
   }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。