1

SmsBroadcastReceiver was not triggering when i received otp in oreo. I have explicitly registered my receiver in fragment instead of not only in manifest.

public class MyFragment extends Fragment{
   @Override
   public View onCreateView(LayoutInflater inflater,
      ViewGroup container, Bundle savedInstanceState) {
      intentFilter = new IntentFilter();
      intentFilter.addAction(Telephony.Sms.Intents.SMS_RECEIVED_ACTION);
      smsBroadcastReceiver = new SmsBroadcastReceiver();
     getActivity().registerReceiver(smsBroadcastReceiver,intentFilter); 
      return inflater.inflate(
              R.layout.fragment_two, container, false);
   }
}

Here it's my SmsReceiverBroadcast class

public class SmsBroadcastReceiver extends BroadcastReceiver {
    public SmsBroadcastReceiver() {
    }
    @Override
    public void onReceive(Context context, Intent intent) {
               Log.d("onRecieve","Otp has been received");
            }
        } catch (Exception e) {
        }
    }

}

And in my manifest,

<receiver
                android:name=".receiver.SmsBroadcastReceiver"
                android:enabled="true"
                android:exported="false"
                >
                <intent-filter>
                    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </receiver>

I'm not getting any trigger in override onReceive() method for the Broadcast receiver. I have found that we need to register a broadcast receiver explicitly. I register my receiver using registerBroadcast().It is not working for me.Also, I referred https://developer.android.com/about/versions/oreo/background.html

I have also tried Do I need to add any other permission to register and triggering the receiver whenever I receive otp?Is my intent filters action(Telephony.Sms.Intents.SMS_RECIEVED_ACTION) correct?

Ajay Jayendran
  • 1,584
  • 4
  • 15
  • 37
  • 1
    Oreo have some restriction in Broadcast Receiver. check this blog link https://medium.com/exploring-android/exploring-background-execution-limits-on-android-oreo-ab384762a66c – Ashok Apr 15 '18 at 04:03
  • try increasing the priority value of intent filter... to a no. like `22222222222222` – Santanu Sur Apr 29 '18 at 01:34
  • checkout this link https://stackoverflow.com/questions/48789572/oreo-broadcastcontroller-sms-received-not-working/50558014#50558014 – Rohit Sharma Jun 01 '18 at 00:50
  • Check my answer [here](https://stackoverflow.com/questions/48789572/oreo-broadcastcontroller-sms-received-not-working/52016035#52016035) ,this worked for me. – shashank chandak Aug 25 '18 at 09:58

0 Answers0