如何检测飞机模式,尤其是果冻光束?

时间:2013-04-03 06:22:11

标签: android

用于检测飞行模式的波纹管代码在果冻光束版本中不起作用。

    // Check for Airplane Mode
    boolean isEnabled = Settings.System.getInt(getContentResolver(),Settings.System.AIRPLANE_MODE_ON,0) == 1;

if (isEnabled) {
// toggle airplane mode
Settings.System.putInt(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);
}

请与我分享您的疑问。提前致谢

2 个答案:

答案 0 :(得分:5)

This Is Code Snippet适用于JB

    /**
* Gets the state of Airplane Mode.
* 
* @param context
* @return true if enabled.
*/
private static boolean isAirplaneModeOn(Context context) {

   return Settings.System.getInt(context.getContentResolver(),
           Settings.System.AIRPLANE_MODE_ON, 0) != 0;

}

Jelly Bean 4.2 中,此设置已移至Settings.Global

答案 1 :(得分:1)

在jellybean中,AIRPLANE Mode设置值将移至全局表。

在SDK文档中,应用程序无法编写全局表。

  

应用程序可以读取这些但不允许写入;与“安全”设置类似,这些设置适用于用户必须通过系统UI或这些值的专用API明确修改的首选项。

有关详细信息,请参阅http://developer.android.com/reference/android/provider/Settings.Global.html