Current location - Quotes Website - Signature design - How to set the system time through code during the Android development process, please give a detailed answer. From first step to realization
How to set the system time through code during the Android development process, please give a detailed answer. From first step to realization

The following Android code is just written casually. It has not been verified whether it can be used. It is for reference only.

The general idea is to execute such a command /system/bin/date -s "2012-06-03 13:12:00"

Because different system date files may not be the same. It may or may not be stored in this location. You have to find the correct location and adjust it yourself.

In addition, the format of the date command is also different. I think it is like this under Android. You can first test whether it is correct in the command terminal of the debugging serial port.

try

{

Process dateexe;

dateexe= Runtime.getRuntime().exec("/system/bin/date ");

String cmd = " -s \"2012-06-03 13:12:00\" ";

dateexe.getOutputStream().write(cmd.getBytes ());

if ((dateexe.waitFor() != 0) {

throw ; }

}

No Guaranteed to work.