SMS Broadcast Receiver not working

前提是你 提交于 2019-12-02 03:06:40

Try following way with highest reading priority value,

<receiver android:name=".SmsListener"
             android:enabled="true"
            android:exported="true"
            android:permission="android.permission.READ_SMS">
    <intent-filter android:priority="2147483647">
        <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
    </intent-filter>
</receiver>

This will surely solve out your problem.

Update from below comment,

Since you are checking on Android version 6.0.1 just follow these steps,

  1. Go to Settings,
  2. Go to Apps
  3. Select your Application
  4. Choose Permissions Option
  5. Enable SMS permission

Found a solution.

First make another app your default SMS app.

Then: Google Hangout --> Settings (Disable merged conversations) --> SMS (Disable SMS)

You are registering broadcast your in your Activity, so it won't work if your app is in background. you can remove this from your Activity and you can register it in Manifest.

ex:

 <receiver android:name=".SmsListener">
    <intent-filter android:priority="999">
        <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
    </intent-filter>
</receiver>

Along with this add permission to recieve sms.

Try this, and it will work

After spending more than an hour I found that RECEIVE_SMS permission is required.

ActivityCompat.requestPermissions(this, 
            new String[]{Manifest.permission.RECEIVE_SMS},
            MY_PERMISSIONS_REQUEST_SMS_RECEIVE);

Prioirty is not required to be set. This should work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!