问题
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