0

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..

4

1 回答 1

2

我假设错误发生在names[0]=0因为names是一个字符串。

如果要读取字符串的第一个字母,请使用

   if ( !names.isEmpty() && names.substring(0,1).equals("0"))
         line1.setText("got it");
   else
         line1.setText("Nil");
于 2015-07-17T08:11:04.527 回答