代码如下:
public static boolean IsAirModeOn(Context context) {
return (Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) == 1 ? true : false);
}
如何切换飞行模式
代码如下:
public static void setAirplaneMode(Context context, boolean enabling) {
Settings.System.putInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, enabling ? 1 : 0);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", enabling);
context.sendBroadcast(intent);
}
如何注册和取消自动飞行时间
注册
代码如下:
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(AIR_ALERT_ACTION);
Parcel out = Parcel.obtain();
air.writeToParcel(out, 0);
out.setDataPosition(0);
intent.putExtra(AIR_RAW_DATA, out.marshall());
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender);取消
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
endingIntent sender = PendingIntent.getBroadcast(context, 0,
new Intent(action), PendingIntent.FLAG_CANCEL_CURRENT);
am.cancel(sender);
如何控制切换飞行模式的硬件(cell,Bluetooth,wifi)
代码如下:
Settings.System.putString(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_RADIOS, air_mode_radios);air_mode_radios为一个这样的字符串,看android源码中android/provider/Settings.java
public static final String AIRPLANE_MODE_ON = "airplane_mode_on";
public static final String RADIO_BLUETOOTH = "bluetooth";
public static final String RADIO_WIFI = "wifi";
public static final String RADIO_CELL = "cell";
public static final String AIRPLANE_MODE_RADIOS = "airplane_mode_radios";
public static final String AIRPLANE_MODE_TOGGLEABLE_RADIOS = "airplane_mode_toggleable_radios";
如果air_mode_radios=“cell,bluetooth,wifi”,这就便是切换飞行模式是切换字符串中的这cell,bluetooth,wifi硬件,我们可以通过设置该字符串的值,来控制这三个硬件是否在切换飞行模式是进行切换状态。 您可能感兴趣的文章:Android主题切换之探究白天和夜间模式AndroidSDK Support自带夜间、日间模式切换详解Android夜间模式最佳实践android基础教程之夜间模式实现示例javascript判断iphone/android手机横竖屏模式的函数Android 听筒模式的具体实现实例Android开发之文件操作模式深入理解Android 情景模式的设置代码Android 如何定制vibrator的各种震动模式M 具体方法三行Android代码实现白天夜间模式流畅切换