How to update system time and time zone?

和自甴很熟 提交于 2020-01-06 07:55:50

问题


I am trying to update the system time and time zone. This is system application. So I gave system application permissions. My code is

    try {

        AlarmManager alarmManager =
                (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(getSelectedDateFormat(mSelectedDateFormat)
                .parse(mEtDate.getText() +" "+ mEtTime.getText()));
        alarmManager.setTimeZone(mSpTimeZone.getSelectedItem().toString());
        alarmManager.setTime(calendar.getTimeInMillis());

    } catch (ParseException e) {
        e.printStackTrace();
    }
}

Here when I update TimeZone and Time at a moment, Time is update wrongly. If I update time alone it update perfectly. Any idea what I am did wrong?


回答1:


All system apps are not permitted to change the time zone.

In your application make file make sure that you have following tag

LOCAL_PRIVILEGED_MODULE := true

Only the system/priv-app are permitted to set the time zone.



来源:https://stackoverflow.com/questions/54550576/how-to-update-system-time-and-time-zone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!