SMS Broadcast Receiver not working

前端 未结 4 1607
不知归路
不知归路 2021-01-23 08:33

Alright, I have tried every solution on Stack and nothing works.My current method registers the \"SmsListener\" receiver from the MainActivity. All I\'m trying to do is initiali

相关标签:
4条回答
  • 2021-01-23 08:47

    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.

    0 讨论(0)
  • 2021-01-23 08:51

    Found a solution.

    First make another app your default SMS app.

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

    0 讨论(0)
  • 2021-01-23 08:55

    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

    0 讨论(0)
  • 2021-01-23 09:02

    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
    0 讨论(0)
提交回复
热议问题