0

I am creating a op-out app. I am using Incomming SMS Broadcast Receiver, I need to check if the incoming message contains a specific keyword:

i.e

From: 656565451

msn: I want to op-out news

code .i.e - "this does not work"

String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();

//check if user message has this keywork
String keyWord_code = "op-out";


Pattern pattern = Pattern.compile("op-out");

if (pattern == keyWord_code ) {
  //Do the op-out function here
}
else {
  //Send message to user 
}
Cho Hee
  • 165
  • 1
  • 11

2 Answers2

0

I see that you are trying to use Regex?

Well, you can try something a little simpler first before going on to RegEx:

if( message.contains(keyWord_code) ){
  // do something
}else{
  // do something else
}
An SO User
  • 24,612
  • 35
  • 133
  • 221
0

I don't know if you have problems with the receiver or what. If you just want to know if the msg body has the word "op-out" you just need the next code:

if(message.contains(keyWord_code) {
//...
} else {
//...
}
jcasero
  • 46
  • 3