2014-10-14 4 views
0

У меня есть mBluetoothGatt.writeDescriptor (дескриптор) или writeCharacteristic (характеристика) для отправки данных на устройства.Как отправить данные на сервер?

, но устройства не могут быть приняты. Я не знаю почему?

Это мой код:

public void writeDataToBel() { 

    if ((gattCharacteristics_send.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) { 
     System.out.println("have permission"); 
    } 
String send_data = "d300000000060000000000000000d900"; 
    gattCharacteristics_send.setValue(send_data); 

    gattCharacteristics_send 
     .setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); 

    boolean sendStatus = mBluetoothGatt 
      .writeCharacteristic(gattCharacteristics_send); 

    System.out.println("status-->" + sendStatus); 
} 

ответ

0

Я решил это:

"d300000000060000000000000000d900" chageTo byte[] 


public static byte[] changeToByte(String sendData) { 
     byte[] myByte = new byte[16]; 
     int[] myInt = new int[16]; 
     for (int i = 0; i < myByte.length; i++) { 
      myInt[i]=Integer.valueOf(sendData.substring(i*2, (i+1)*2), 16); 
     } 
     for (int i = 0; i < myByte.length; i++) { 
      myByte[i] = (byte) myInt[i]; 
     } 
     return myByte; 
} 
0

Убедитесь, что characterisitic вы пишете имеет разрешение на запись. Вы можете выполнить проверку следующим образом:

if((gattCharacteristics_send.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) { 
     gattCharacteristics_send.setValue(send_data); 
     boolean sendStatus = mBluetoothGatt.writeCharacteristic(gattCharacteristics_send); 
} 
+0

разрешения. –

+0

Это мой код. можно распечатать иметь разрешение. –

Смежные вопросы