Ander Acosta Ander Acosta - 4 days ago 5
Android Question

SMS Broadcast Receiver not called on Android 6

I am trying to capture the SMS received on the phone, but when the phone receives an SMS message the method 'onReceive' is not called. This is my code:

I have the BroadcastReceiver is declared in the 'AndroidManifest.xml' inside the tag 'application':

<receiver android:name=".util.IncomingSmsReceiver"
android:exported="true">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>


This is the IncomingSmsReceiver.java

public class IncomingSmsReceiver extends BroadcastReceiver {

public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";

@Override
public void onReceive(Context context, Intent intent) {

Log.i(TAG, "onReceive executed");
if (intent.getAction().equals(SMS_RECEIVED)) {
...
}
}
}


I'm doing the tests on an emulator Google Nexus 5 with Android 6. When I send a sms (fake) in the emulator a notification appears as if it was received really well and I can use it in the default application that brings the emulator. In the logcat of Android Studio does not appear that you have run the method
onReceive
, or the code written inside.I've tried to change the priority, I've tried using
android:enabled="true"
, I've tried using
registerReceiver
and I have not gotten it to work. Does anyone know if I miss something?

Answer

Are you using a default messaging app with "Disable other apps" flag on?

Please see this:

"android.provider.Telephony.SMS_RECEIVED" not working on my device (HTC Wildfire) - how to debug?

Edit:

Since you are using Android 6, you should use the new permissions model. Check this out: http://developer.android.com/training/permissions/requesting.html

Comments