我是靠谱客的博主 冷傲胡萝卜,最近开发中收集的这篇文章主要介绍Android 时区设置以及设置系统属性的分析,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

在开发android系统设置的过程中会涉及许多内容。其中很简单的时区设定就包含很多内容。前面分析的设置时间自动同步的相关内容,下面接着分析一下系统中时区设定的相关内容。

以Android 5.1.1 LMY48M这个版本为例说明:
在时区设定里会调用到SettingssrccomandroidsettingsZonePicker.java这个文件其中:

  @Override
    public void onListItemClick(ListView listView, View v, int position, long id) {
        // Ignore extra clicks
        if (!isResumed()) return;
        final Map<?, ?> map = (Map<?, ?>)listView.getItemAtPosition(position);
        final String tzId = (String) map.get(KEY_ID);

        // Update the system timezone value
        final Activity activity = getActivity();
        final AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
        alarm.setTimeZone(tzId);
        final TimeZone tz = TimeZone.getTimeZone(tzId);
        if (mListener != null) {
            mListener.onZoneSelected(tz);
        } else {
            getActivity().onBackPressed();
        }
    }

完成了时区的设定,这么看来完成这件事情的是AlarmManager这个类,为了知其然更要知其所以然我们继续跟进AlarmManager

    /**
     * Set the system default time zone.
     * Requires the permission android.permission.SET_TIME_ZONE.
     *
     * @param timeZone in the format understood by {@link java.util.TimeZone}
     */
    public void setTimeZone(String timeZone) {
        try {
            mService.setTimeZone(timeZone);
        } catch (RemoteException ex) {
        }
    }

可见AlarmManager也是调用AlarmManagerService.java这个来实现的,继续跟进,在这个服务中

 public void setTimeZone(String tz) {
        mContext.enforceCallingOrSelfPermission(
                "android.permission.SET_TIME_ZONE",
                "setTimeZone");
        long oldId = Binder.clearCallingIdentity();
        try {
            if (TextUtils.isEmpty(tz)) return;
            TimeZone zone = TimeZone.getTimeZone(tz);
            // Prevent reentrant calls from stepping on each other when writing
            // the time zone property
            boolean timeZoneWasChanged = false;
            synchronized (this) {
                String current = SystemProperties.get(TIMEZONE_PROPERTY);
                if (current == null || !current.equals(zone.getID())) {
                    if (localLOGV) {
       

最后

以上就是冷傲胡萝卜为你收集整理的Android 时区设置以及设置系统属性的分析的全部内容,希望文章能够帮你解决Android 时区设置以及设置系统属性的分析所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部