一下这些是我查看系统各个模块的源码总结的一些接口方法:
(以下各个接口的调用需要导入framework的Jar包或者直接放在服务器环境下编译才能使用)
查询当前模式状态:
public static boolean isAirplaneModeOn(Context context) {
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
开关飞行模式:
public static void setAirplaneModeOn(Context mContext, boolean enabling) {
// Change the system setting
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, enabling ? 1 : 0);
// Update the UI to reflect system setting
// Post the intent
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", enabling);
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
}
设置系统是否自动更新日期:
public static void setAutoSysDate(Context mContext, boolean autoEnabled) {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.AUTO_TIME, autoEnabled ? 1 : 0);
}
设置系统是否自动更新时区:
public static void setAutoSysZone(Context mContext, boolean autoZoneEnabled) {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.AUTO_TIME_ZONE, autoZoneEnabled ? 1 : 0);
}
设置是否24小时制:
private static final String HOURS_12 = "12";
private static final String HOURS_24 = "24";
public static void set24Hour(Context mContext, boolean is24Hour) {
Settings.System.putString(mContext.getContentResolver(),
Settings.System.TIME_12_24, is24Hour ? HOURS_24 : HOURS_12);
}
判断系统当前是否24小时制:
public static boolean is24Hour(Activity mActivity) {
return DateFormat.is24HourFormat(mActivity);
}