Am try to Monitoring Incoming SMS in my App. From Android Side they done some change for Monitoring incoming SMS from API 19.
Can't Track incoming Message in Background(at the time of App not in Background & Mobile Screen in Off State) in API 23.
In Android Document said Can't Track Incoming SMS in Background if your app is not as a Default Message App From API 19.
Ref:- Getting Your SMS Apps Ready for KitKat
But its working on My API 21(LOLLIPOP) device. It will not working on API 23(Marshmallow) devices. When Devices Screen is on or the app is open means it Working in API 23(Marshmallow) also.
Can You Please Update Me Is there any Way to Track Incoming Message in Background in API 23(Marshmallow).
Manifest Code
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<receiver
android:name=".SMSReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="5822">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Here My Java Code
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.telephony.SmsMessage;
public class SMSReceiver extends BroadcastReceiver {
public static final String BROADCAST = "SMS_RECEIVER";
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
Intent broadcast_intent;
String message_body = "", originAddress;
StringBuilder bodyText;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(SMS_RECEIVED)) {
broadcast_intent = new Intent(BROADCAST);
Bundle bundle = intent.getExtras();
SmsMessage[] messages;
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
messages = new SmsMessage[pdus.length];
bodyText = new StringBuilder();
for (int i = 0; i < messages.length; i++) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String format = bundle.getString("format");
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
} else {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
originAddress = messages[i].getOriginatingAddress().toUpperCase();
bodyText.append(messages[i].getMessageBody());
}
message_body = bodyText.toString();
}
}
}
}
Basically you can register a broadcast receiver to listen for
SMS_Receive
and check out the following.