我如何拆分,从BLE装置接收到的if else检查和显示在TextView中值的字符串中值、字符串、装置、BLE

2023-09-07 08:43:16 作者:女人、爱你痛到撕心裂肺

在我的Andr​​oid应用我从BLE设备接收数据,就像这样10100201201511(它包括日期,时间和其他属性)。

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

我希望我接受它作为一个字符串,我要检查的价值和TextView中显示。

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

我的要求是

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

不过,我总是得到这样数组类型预期的错误;发现'java.lang.String中

我目前的code是:

        @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帮我解决这个..

Plz help me to resolve this..

推荐答案

我想在名称出现错误[0] = 0 ,因为名称是一个字符串。

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