Home > OS >  BroadcastReciever for SMS_RECEIVED_ACTION registered in manifest not working
BroadcastReciever for SMS_RECEIVED_ACTION registered in manifest not working

Time:08-21

Registering an SMS broadcast receiver in the Manifest doesn't seem to work anymore.

I'm aware that Android recently locked down the manifest broadcast receivers however the SMS_RECEIVED_ACTION appears to be on the exception list.

My receiver looks like this:

class SmsReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        if (intent.action != SMS_RECEIVED_ACTION) return
        val messages = getMessagesFromIntent(intent)
        for (s in messages) {
            Log.i("SmsReceiver", s.displayMessageBody)
            Toast.makeText(context, s.displayMessageBody, Toast.LENGTH_LONG).show()
        }
    }
}

And registered in the manifest:

    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />

    <application
        ...
        tools:targetApi="33"
        android:enabled="true">
        <receiver
            android:name=".SmsReceiver"
            android:enabled="true"
            android:exported="false"
            android:permission="android.permission.BROADCAST_SMS,android.permission.RECEIVE_SMS">
            <intent-filter android:priority="2147483647">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

As you can see, I've been combining tricks from SO for a while and none have proved fruitful as yet. Hopefully it's something stupid, help appreciated :)

CodePudding user response:

Delete android:permission="android.permission.BROADCAST_SMS,android.permission.RECEIVE_SMS".

There is no permission named android.permission.BROADCAST_SMS,android.permission.RECEIVE_SMS. android:permission does not take a comma-delimited list. And, you do not need that attribute.

CodePudding user response:

I guess you should change android:exported="true"

  • Related