我将如何拆分从ble设备接收的字符串,以便if else检查并在Textview上显示值

时间:2015-07-17 07:51:23

标签: android android-bluetooth android-ble

在我的Android应用程序中,我从我的ble设备接收数据,如10100201201511(包括日期,时间和其他属性)。

我希望我收到它作为字符串,我想检查该值并将其显示在textview上。

我的要求是

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

但我总是遇到像Array type expected; found 'Java.lang.String'

这样的错误

我目前的代码是:

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

1 个答案:

答案 0 :(得分:2)

我认为错误发生在root@host1 [/usr/src]# scp ftpdelete.sh user@host@scp.adrive.com:/mysql-only/ scp: /mysql-only/: Is a directory ,因为names[0]=0是一个字符串。

如果您想阅读字符串的第一个字母,请使用

names