如何在 Android 上检测飞行模式? [英] How can one detect airplane mode on Android?

查看:35
本文介绍了如何在 Android 上检测飞行模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有代码可以检测 Wi-Fi 是否已主动连接.如果启用飞行模式,该代码会触发 RuntimeException.无论如何,我想在此模式下显示单独的错误消息.如何可靠地检测 Android 设备是否处于飞行模式?

I have code in my application that detects if Wi-Fi is actively connected. That code triggers a RuntimeException if airplane mode is enabled. I would like to display a separate error message when in this mode anyway. How can I reliably detect if an Android device is in airplane mode?

推荐答案

/**
* 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;

}

这篇关于如何在 Android 上检测飞行模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆