Search code examples
androidandroid-bluetoothandroid-ble

How will i Split a String that received from a ble device for if else checking and display a value on Textview


In my Android app I receive data from my ble device as something like 10100201201511 ( it includes date,time and other attributes).

I hope I received it as a string, I want to check that value and display it on textview.

My Requirement is

If (position1=0){
  //display yes in Text view
}else
{ // display No in Textview 
}  

But I always get errors like Array type expected; found 'Java.lang.String'

My current code is:

        @Override
        public void onCharacteristicRead(BluetoothGatt gatt,
                                         BluetoothGattCharacteristic characteristic, int status) {
            if (status == BluetoothGatt.GATT_SUCCESS) {
                if (BleUuid.READ_TIME
                        .equalsIgnoreCase(characteristic.getUuid().toString())) {
                    final String names = characteristic.getStringValue(0);


                    if (names[0]=0){
                        line1.setText("got it");
                    }
                    else{
                        line1.setText("Nil");
                    }

Plz help me to resolve this..


Solution

  • I assume the error occurs at names[0]=0 because names is a string.

    If you want to read the first letter of the string use

       if ( !names.isEmpty() && names.substring(0,1).equals("0"))
             line1.setText("got it");
       else
             line1.setText("Nil");