Send text to My Band 2 from Android BLE

4

Does anyone know how to send text to the MiBand 2 from android?

So far I am able to send numbers but not strings and I do not know how to do.

        @Override
        public void onServicesDiscovered(final BluetoothGatt gatt, int status)
        {
            super.onServicesDiscovered(gatt, status);
            Log.d(TAG, "onServicesDiscovered status="+status);

            if (status == BluetoothGatt.GATT_SUCCESS) {
                charact_2A06 = gatt.getService(Constants.UUID_SERVICE_1802).getCharacteristic(Constants.UUID_CHARACTERISTIC_2A46);
                isConnected = true;
            }
        }

        @Override
        public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
        {
            super.onCharacteristicChanged(gatt, characteristic);
            Log.d(TAG, "onCharacteristicChanged "+characteristic.getUuid()+" "+ Arrays.toString(characteristic.getValue()));
        }

        @Override
        public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
            super.onCharacteristicWrite(gatt, characteristic, status);
            Log.d(TAG, "onCharacteristicWrite "+characteristic.getUuid()+" "+ Arrays.toString(characteristic.getValue()));
            if(mWait!=null && mWait.getCount()>0)
                mWait.countDown();
        }
    };

 public void enviarDatos(String dato){

        if(!isConnected){
            connect();
        }


        try {


            byte b =Byte.valueOf(dato);

            charact_2A06.setValue(new byte[]{-3,2,b,(byte)0});
            mGatt.writeCharacteristic(charact_2A06);


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


    }
    
asked by Mario Moure 02.06.2017 в 09:17
source

1 answer

1

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 11.07.2017 / 15:41
source