我的应用程序中有代码可检测 Wi-Fi 是否处于 Activity 状态。如果启用了飞行模式,该代码将触发 RuntimeException。无论如何,我想在此模式下显示单独的错误消息。如何可靠地检测 Android 设备是否处于飞行模式?
最佳答案
/**
* 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.Global.AIRPLANE_MODE_ON, 0) != 0;
}
关于java - 如何在 Android 上检测飞行模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4319212/