前段时间刚接触安卓,进公司后,上级交代先搞个修改系统时间的,查阅了大量资料。成功了有一下两个方法:
1、自己的源码可以用签名的方法修改,这个网上一查一大片。
2、修改已经ROOT过的手机可以这样:
public void testDate(){
try {
Process process = Runtime.getRuntime().exec("su");
String datetime="20131023.112800";
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("setprop persist.sys.timezone GMT\n");//时区,会在设置时间的基础上+8小时
os.writeBytes("/system/bin/date -s "+datetime+"\n");
os.writeBytes("clock -w\n");
os.writeBytes("exit\n");
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
}