2017-03-24 6 views
0

私はfff2特性から値を取得する必要があります。 その特性は01または00を返しますbluetoothから配列値を取得低エネルギーfff2 Javaの特性

値を得るには?
thisは私が欲しい値の例です。

public boolean readCharacteristic(){ 

    //check mBluetoothGatt is available 
    if (bluetoothGatt == null) { 
     Log.e(TAG, "lost connection"); 
     return false; 
    } 
    BluetoothGattService Service = bluetoothGatt.getService(UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb")); 
    if (Service == null) { 
     Log.e(TAG, "service not found!"); 
     return false; 
    } 
    BluetoothGattCharacteristic charac = Service 
      .getCharacteristic(UUID.fromString("0000fff2-0000-1000-8000-00805f9b34fb")); 


    if (charac == null) { 
     Log.e(TAG, "char not found!"); 
     return false; 
    } 
     final byte[] data = charac.getValue(); // return null 
     String s2 = new String(data); 

     Log.i("READ", s2); 
     boolean status = true; 

     return status; 

} 

感謝..

+0

お願いします。 – 7383

+0

これは私のコード@ 7383です –

答えて

0
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { 

     if (status == BluetoothGatt.GATT_SUCCESS) { 
      byte[] data = characteristic.getValue(); 
     } 
    } 

必要に応じてHexフォーマットにバイト配列に変換します。 これは役に立ちます。

関連する問題