系统原生设置总结的各种接口方法
2016-11-28 16:10
232 查看
一下这些是我查看系统各个模块的源码总结的一些接口方法:
(以下各个接口的调用需要导入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);
}
(以下各个接口的调用需要导入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);
}
相关文章推荐
- Android中 跳转到系统设置界面方法总结
- 【caffe 学习笔记之2】 Win10系统下Caffe的Matlab接口设置方法与猫狗识别案例(哈士奇/松狮/波斯猫)
- 【caffe学习笔记之5】Win10系统下Caffe的Python接口设置方法并绘制网络结构图
- LINUX中系统调优与安全设置的方法总结
- Android开发中设置系统全局属性方法总结
- 在各种Linux系统的服务器上设置时间同步的方法
- LINUX中系统调优与安全设置的方法总结:
- 在ECC系统中设置外部断点进行ABAP接口程序Debug的方法
- 对基于qmail的smtp用户验证的总结和完整安装设置方法
- 十招提高Linux系统安全性的设置方法
- ghost版系统安全设置方法
- 华为各种型号交换机端口镜像配置方法总结
- pjblog中添加各种GOOGLE广告的方法总结
- 软件、程序脱壳的各种方法大总结
- 收集:2003系统上关系IIS的各种设置(未完)
- 经验总结系统文件无法打开故障解决方法