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

帅比萌擦擦* 提交于 2019-12-08 10:25:03

问题


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


回答1:


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");


来源:https://stackoverflow.com/questions/31470865/how-will-i-split-a-string-that-received-from-a-ble-device-for-if-else-checking-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!