Send Text to My Band 2

0

I would like to send a text from an application in Android to MiBand 2 , I have managed to send numbers in the form of beats, but I do not know how to send text.

contants.java

public class Consts {//this is common for all BTLE devices. see http://stackoverflow.com/questions/18699251/finding-out-android-bluetooth-le-gatt-profiles
    public static final String BASE_UUID = "0000%s-0000-1000-8000-00805f9b34fb";

    public static final UUID UUID_SERVICE_GENERIC = UUID.fromString(String.format(BASE_UUID, "1800"));
    public static final UUID UUID_SERVICE_1802 = UUID.fromString(String.format(BASE_UUID, "1802"));
    public static final UUID UUID_SERVICE_MIBAND_SERVICE = UUID.fromString(String.format(BASE_UUID, "FEE0"));
    public static final UUID UUID_SERVICE_MIBAND2_SERVICE = UUID.fromString(String.format(BASE_UUID, "FEE1"));
    public static final UUID UUID_SERVICE_HEARTBEAT = UUID.fromString(String.format(BASE_UUID, "180D"));
    public static final UUID UUID_CHARACTERISTIC_2A06 = UUID.fromString(String.format(BASE_UUID, "2A06"));//caracteristica nivel de alerta
    // General service
    public static final UUID UUID_CHARACTERISTIC_DEVICE_NAME = UUID.fromString(String.format(BASE_UUID, "2A00"));

    // Miband service 1
    public static final UUID UUID_BUTTON_TOUCH = UUID.fromString("00000010-0000-3512-2118-0009af100700");//servicio botón


BLEMiBand2Helper.java

@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status){
            Log.d(TAG, "Write successful: " + 
            Arrays.toString(characteristic.getValue()));
            raiseonWrite(gatt,characteristic,status);
            super.onCharacteristicWrite(gatt,characteristic,status);}

public void sendData(String value){
        if(!isConnectedToGatt){
            connect();
        }
        try {


            byte mens=Byte.valueOf(value);
            characteristic.setValue(new byte[]{-3, 2,mens, (byte) 0});
           // characteristic.setValue(value.getBytes(Charset.defaultCharset().forName("Utf-8"))}); Esto envia pero no muestra nada en la pulsera
            myGatBand.writeCharacteristic(characteristic);



        }catch (Exception e){
            e.printStackTrace();
        }
    }

 public void raiseonWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,int status) {
        // Notify everybody that may be interested.
        for (BLEAction listener : listeners)
            listener.onWrite( gatt,characteristic,status);
    }
    
asked by Mario Moure 12.06.2017 в 14:49
source

1 answer

0

Solved the My band2 already receives text, see the code in:

link

public void sendData(String value) {
if (!isConnectedToGatt) {
    connect();
}
try {
    byte alert=Consts.alert1;
    byte sms=Consts.mensaje;

    byte [] param=new byte[]{sms,alert};
    byte[] bytes = value.getBytes(StandardCharsets.US_ASCII);

    byte[] mensaje= new byte[param.length+bytes.length];
    System.arraycopy(param,0,mensaje,0,param.length);
    System.arraycopy(bytes,0,mensaje,param.length,bytes.length);

    characteristic.setValue(mensaje);
    myGatBand.writeCharacteristic(characteristic);




    /********
     * EJEMPLO: ESTO ENVIA LA PALABRA TEST CON EL ICONO DE SMS SIEMPRE QUE EL SERVICIO SEA 1811 Y LA CARACTERISRICA 2a46.
     * characteristic.setValue(new byte[]{5,1,84,101,115,116});
     * myGatBand.writeCharacteristic(characteristic);
     *********/


} catch (Exception e) {
    e.printStackTrace();
}

}

    
answered by 13.07.2017 / 13:14
source