【发布时间】:2017-02-01 14:46:56
【问题描述】:
我想检测我的设备是否处于飞行模式以取消活动的网络操作。我该怎么做?
【问题讨论】:
标签: android android-networking
我想检测我的设备是否处于飞行模式以取消活动的网络操作。我该怎么做?
【问题讨论】:
标签: android android-networking
你可以使用这个方法:
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isAirplaneModeOn(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
} else {
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
}
【讨论】: