6
An App receives an SMS and from the text performs a function. For this it is necessary to read the SMS and make the comparison in the APP, but for this must read, word by word, line by line or make a comparison if it contains such a word in this SMS.
SMS will have the following content.
If a change of status occurs:
MONIT-110
E05-ATI
E06-DES
And that of all exits:
STATUS-110
E01-DES
E02-DES
E03-DES
E04-DES
E05-DES
E06-DES
E07-DES
E08-DES
E09-DES
E10-DES
E11-DES
S01-DES
S02-DES
S03-DES
S04-DES
S05-DES
S06-DES
For each of these lines have a different command to execute.
Code responsible for MSG received:
public class ReceberSms extends BroadcastReceiver {
private static final String CATEGORIA = "acqua";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(CATEGORIA, ">" + intent.getAction());
Sms sms = new Sms();
//Lê a mensagem
SmsMessage msg = sms.receberMensagem(intent);
String celular = msg.getDisplayOriginatingAddress();
String mensagem = msg.getDisplayMessageBody();
//pegar essa msg e jogar nas configurações
String texto = "ReceberSms: recebeu sms[" + celular + "] -> " + mensagem;
Log.i(CATEGORIA, texto);
Toast.makeText(context, texto, Toast.LENGTH_SHORT).show();
}
}//fim
I didn’t quite understand what the doubt is... But I believe it’s like breaking the text in tokens?
– Wakim
The text that I receive contains commands to doubt is how I can read the content of the text to identify the commands that are in it. I think it would be like breaking the text into tokens but I don’t know how to do it.
– Jéssica Luiza
Seeing that you already have the full text, I think just call the method
split
, passing the command tab. It would be nice to maybe include an example to help find the solution.– Wakim