0

I have read several questions in stackoverflow including this, this and this, but they did not help me to fix my problem.

I have described my broadcast receiver in android manifest to receive incoming SMSs, but it does not work on version 6.0(Marshmallow) and 7.0(Noughat) altought it works in lower versions like 4.0.

My application have permission to read and receive SMS both in manifest and by granting permissions in run-time however onReceive off my Broacast receiver is never fired. I also tried to set priority to MAX_INT(i.e. 2147483647) but it did not help.

Here is my brodcast receiver description in manifest:

<receiver
    android:name="com.package.receiver.IncomingSms"
    android:enabled="true"
    android:permission="android.permission.READ_SMS">
    <intent-filter android:priority="999">
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>
VSB
  • 9,825
  • 16
  • 72
  • 145
  • I'm not sure what you mean by the comment on the answer below, but the `permission` attribute you have in your snippet is incorrect. That attribute specifies the permission the _broadcast sender_ must hold. If you include one there at all, it needs to be the `BROADCAST_SMS` one. – Mike M. Nov 27 '17 at 21:38

1 Answers1

0

This is a sample code which is working fine in marshmallow as well as nougat

Mainifest code :

 <receiver
            android:name=".utlis.SMSReceiver"
            android:exported="true"
            android:permission="android.permission.BROADCAST_SMS">
            <intent-filter android:priority="999">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

Reciver class code :

 public void onReceive(final Context context, Intent intent) {
        System.out.println(".............................123........................");
        final Bundle bundle = intent.getExtras();
        Log.d(TAG, "onReceive: ");
}

Permission needed:

 <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
pankaj yadav
  • 424
  • 4
  • 10