How to set the AIRPLANE_MODE_ON to “True” or ON?

后端 未结 3 854
鱼传尺愫
鱼传尺愫 2020-11-27 16:53

I am planning to drop a call and I find this as one of workaround for that. How do I activate the airplane mode via code?

This way I will drop the call based on so

相关标签:
3条回答
  • 2020-11-27 17:25

    Please keep in mind that this is no longer possible starting from Android 4.2 and above.

    http://developer.android.com/reference/android/provider/Settings.Global.html#AIRPLANE_MODE_ON

    0 讨论(0)
  • 2020-11-27 17:29

    See the blog article Android: Controlling Airplane Mode ,

    Works only upto API 16

    // Toggle airplane mode.
    Settings.System.putInt(
          context.getContentResolver(),
          Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);
    
    // Post an intent to reload.
    Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
    intent.putExtra("state", !isEnabled);
    sendBroadcast(intent);
    

    where isEnabled is whether airplane mode is enabled or not.

    0 讨论(0)
  • 2020-11-27 17:34
      public static boolean getAirplaneMode(Context context) {
          try {
          int airplaneModeSetting = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON);
          return airplaneModeSetting==1?true:false;
        } catch (SettingNotFoundException e) {
          return false;
        }
      }
    
    0 讨论(0)
提交回复
热议问题