请参阅下面的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IntentFilter intentFilter = new IntentFilter("android.intent.action.SERVICE_STATE");
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("AirplaneMode", "Service state changed");
Toast.makeText(getApplicationContext(), "Service state changed", Toast.LENGTH_LONG).show();
boolean isEnabled = isAirplaneModeOn(context);
/* setSettings(context, isEnabled?1:0);
Intent intent_mode = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent_mode.putExtra("state", !isEnabled);
context.sendBroadcast(intent_mode);*/