您的位置:首页 > 移动开发 > Android开发

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

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);

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息