Here is the code:
AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<receiver
android:name=".SmsListener"
android:exported="true" android:enabled="true">
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
</intent-filter>
</receiver>
Just a simple "SmsListener" as follows:
public class SmsListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle bundle = intent.getExtras();
Also requesting permissions at run time is set as well and application is granted with required permissions.
if(ContextCompat.checkSelfPermission(context, "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED) {
I tested on most of the devices (iOS as well) it works fine but seems Android 6.0 ignores BroadcastReceiver and "onReceive" does not get triggered.
When I change Default Messaging app from "Messages" to "Hangouts" or "Messenger" then onReceive gets triggered.
Any idea why Android 6.0 and above acts like this?