系统原生设置总结的各种接口方法

来源:互联网 发布:华为平板有windows系统 编辑:程序博客网 时间:2024/06/05 11:21

一下这些是我查看系统各个模块的源码总结的一些接口方法:

(以下各个接口的调用需要导入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);
    }


0 0