You just need to register a BroadcastReceiver with IntentFilter of "android.provider.Telephony.SMS_RECEIVED". Then you can get a received message from the intent like this:
try {
Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
for (Object msg : messages) {
byte[] bytes = (byte[]) msg;
SmsMessage message = SmsMessage.createFromPdu(bytes);
String messageBody = message.getDisplayMessageBody(); // this is your SMS message body
} catch (Exception e) {
//catch exception here
}
You will need to add a <uses-permission android:name="android.permission.RECEIVE_SMS"/> to your AndroidManifest.xml and handle Runtime permissions for API > 23.
2
solved Read last incomming SMS from phone inbox