一个人怎么可以检测到飞行模式在Android? [英] How can one detect airplane mode on Android?
本文介绍了一个人怎么可以检测到飞行模式在Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有code。在我的应用程序检测如果Wi-Fi是否已连接。这code触发一个RuntimeException如果启用飞行模式。我想反正显示,当在此模式下单独的错误消息。我怎样才能可靠地检测如果一个Android设备处于飞行模式?
解决方案
/ **
*获取的飞行模式状态。
*
* @参数方面
* @返回true,如果启用。
* /
私有静态布尔isAirplaneModeOn(上下文的背景下){
返回Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON,0)!= 0;
}
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.System.AIRPLANE_MODE_ON, 0) != 0;
}
这篇关于一个人怎么可以检测到飞行模式在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文