Permission Denial: broadcasting Intent act=android.provider.Telephony.SMS_RECEIVED

1.9k views Asked by At

My app reads incoming SMS. I have implemented receiver, added permission and receiver in Manifest but when SMS is received I get following message in logcat.

12-29 13:25:00.081 2030-2044/? W/BroadcastQueue: Permission Denial: broadcasting Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x8000010 (has extras) } from com.android.phone (pid=5234, uid=1001) is not exported from uid 10665 due to receiver com.tatvic.vatsal.test_uninstall_tracking/com.tatvic.lib.uit.SmsReceiver

Manifest :

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

<application
    ....>
    <receiver android:name=".SmsReceiver"
        android:exported="false">
        <intent-filter android:priority="1000">
            <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
        </intent-filter>
    </receiver>
</application>

SmsReceiver:

public class SmsReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION) && intent.getExtras() != null) {
            Log.d("MessageReceived", "MessageReceived");
        }
    }
}

I have read similar threads on Stackoverflow but nothing helps. I have tested this on Marshmallow OS and have allowed SMS permission.

How can I get received SMS in my app?

Edit:

I am able to receive sms in my app when app is opened or is in background after setting exported = true in receiver tag of Menifest file. But when app is closed I get the following message in logcat and cannot receive sms.

12-29 14:28:27.111 2030-2044/? I/ActivityManager: Start proc 8428:com.tatvic.vatsal.test_uninstall_tracking/u0a666 for broadcast com.tatvic.vatsal.test_uninstall_tracking/com.tatvic.lib.uit.SmsReceiver

1

There are 1 answers

3
frogatto On

Since your receiver is supposed to be invoked outside of your application, you should set its android:exported to true.

Set to true if this component is available for use by other applications. Comes from android:exported of the <activity>, <receiver>, <service>, or <provider> tag.