Implicit Broadcast Receiver on Android Oreo and higher

Viewed 238

My Broadcast receiver is not working when my application has been cleared from recently used apps. I am able to receive broadcasts and see the toast when the app is active. I am aware of the background execution limits that have been imposed from Oreo. According to the documentation, ACTION_PHONE_STATE_CHANGED is one of the exceptions that can register broadcast receivers for implicit broadcasts. But I am not able to see the toast after application has been cleared from recently used apps tab. Is anyone facing similar problems? Here is my code that I used.

Permission Used - AndroidManifest.xml

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />

Receiver - AndroidManifest.xml

<receiver android:name=".receiver.IncomingCallReceiver"
          android:enabled="true"
          android:exported="true">

    <intent-filter>
        <action android:name="android.intent.action.PHONE_STATE" />
    </intent-filter>
</receiver>

Receiever Class - IncomingCallReceiver.java

public class IncomingCallReceiver extends BroadcastReceiver {

    private static final String TAG = "IncomingCallReceiever";

    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getStringExtra(TelephonyManager.EXTRA_STATE)
            .equals(TelephonyManager.EXTRA_STATE_RINGING)){
            Toast toast=Toast.makeText(context,message,Toast.LENGTH_LONG);
            toast.show();
        }
    }
}
0 Answers
Related