问题
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