I have an test application that connects with a bluetooth and receives and sends data. Everything is ok here.
My problem is that I need to handle the return before the set TextView.
If I received "OK," I need to return "Turn On".
If I received "OFF", I need to return "Turn Off".
I am not able to manipulate the data. Some tips here?
My Code:
void appendLog(){
bluetoothIn = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == handlerState) {
String readMessage = (String) msg.obj;
recDataString.append(readMessage);
int endOfLineIndex = recDataString.indexOf("\r\n");
while ((endOfLineIndex= recDataString.indexOf("\r\n")) > 0){
String dataInPrint = recDataString.substring(0, endOfLineIndex);
txtString.setText(dataInPrint);
Log.d("BT", "Received: " + dataInPrint);
String aux = dataInPrint.toString();
// If i received "OK" I need return in TV "Turn on"
if(aux == "OK"){
Log.d("BT", "OK");
//txtString.setText("Turn on");
}else{
Log.d("BT, "NOK");
//txtString.setText("Turn off");
}
recDataString.delete(0, recDataString.length());
}
}
}
};
}
Android Monitor:
07-08 21:06:19.000 29972-29972/com.test D/BT: Received: OK
07-08 21:06:19.000 29972-29972/com.test D/BT: NOK
Tks for all and sorry for my english ;)