合并来自 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 (将#修改为@)