Broadcast receiver with AIRPLANE_MODE not working with SDK 26

Viewed 1730

Normaly, I use a simple code to put a Toast when the user change the AIRPLANE_MODE, and it work using targetSdkVersion 25.

My AirPlaneModeReceiver :

    public class AirPlaneModeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Toast.makeText(context, "I receive a Broadcast", Toast.LENGTH_SHORT).show();

    }
}

The part of the Manifest where I declare my Receiver :

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

But when I change the target SDK version to targetSdkVersion 26, it's not working at all... Why ?

2 Answers
public class AirplaneModeChangeReceiver extends BroadcastReceiver {
 
    @Override
    public void onReceive(Context context, Intent intent) {
 
        if (isAirplaneModeOn(context.getApplicationContext())) {
            Toast.makeText(context, "AirPlane mode is on", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(context, "AirPlane mode is off", Toast.LENGTH_SHORT).show();
        }
    }
 
Related