2016-09-15 16 views
-1

Android 4.4.2 OS用に書かれた同じコードで奇妙なシナリオが発生するSamsungとSamsung(A8)Android 5.1.1。上記のコードでAndroid Bleの書き込み

if(mBluetoothGattCharacteristic==null){ 
      return; 
     } 

     byte [] mCommandData=new byte[64]; 
     mCommandData[0]=Constants.REMOTE_CMD; 
     mCommandData[1]=(byte) mRemoteCommand; 

     mBluetoothGattCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); 

     boolean isUpdated= mBluetoothGattCharacteristic.setValue(mCommandData); 
     boolean isWriteDone=mBluetoothGatt.writeCharacteristic(mBluetoothGattCharacteristic); 
     LogUtils.i("LOG", "Ble Write set is---"+ isUpdated + " Characteristics Write done"+ isWriteDone); 

     /** 
     * Create New Command Release Key 
     */ 

     byte [] mCommandRelease=new byte[64]; 

     mCommandRelease[0]=Constants.REMOTE_CMD; 
     mCommandData[1]=(byte)Constants.IR_KEY_RELEASE; 

     isUpdated= mBluetoothGattCharacteristic.setValue(mCommandData); 
     isWriteDone=mBluetoothGatt.writeCharacteristic(mBluetoothGattCharacteristic); 
     LogUtils.i("LOG", "Ble Write set is---"+ isUpdated + " Characteristics Write done"+ isWriteDone); 

アンドロイド4.4.2用writeCharacteristicコマンド書き込みの両方に当てはまり与えます。

しかし、アンドロイドの場合はそれが初めての書き込みに真与え5.1.1およびそれがwriteCharacteristic

で偽与える次の書き込みを続けるだとき、今私は思っています解決策は、私は待つ必要がアンドロイド5.1.1でありますonCharacteristicWriteの場合は、次のコマンドを書き込みます。

このような問題がある場合は、私に案内してください。これはサムスンのデバイスでのみ起こりますか?今私はonCharacteristicWriteに私の次のコマンドを置くことによって、問題を整理するために

答えて

-1

私たちは、このようなコードを書くべきではないことが判明:

BluetoothGattCharacteristic.setValue(mCommandData); 
boolean isWriteDone=mBluetoothGatt.writeCharacteristic(mBluetoothGattCharacteristic); 

再度、次のコマンド送信:

BluetoothGattCharacteristic.setValue(mNextCommdn); 
boolean isWriteDone=mBluetoothGatt.writeCharacteristic(mBluetoothGattCharacteristic); 

GATTプロファイルで2回の書き込み操作を実行しようとすると、最初の操作のみが正常に実行されます。

私は次のコマンドベースを最初のコマンドの受信結果に書きます: これはonCharacteristicWriteで受信されます。

+1

これは正しい解決策です。 AndroidのBLE APIでは、一度に1つのGATT操作しか実行できません。 – Emil