Basically, need to create a Broadcast receiver. Some of the devices, we may need to also give the priority so that the message is received.
public class SmsListener extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) {
for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
String messageBody = smsMessage.getMessageBody();
}
}
}
}
Below need to be added in the manifest file
Also, below permission should be given in the manifest file.
References:
No comments:
Post a Comment