之前看很多修改系统时间得都是4.0之前用的格式,现在7.0之后的格式有所改变,请大家参考比对
建议先用adb命令调试,可以的话在加入代码也一定可以。但要记得 root 和 加权限
/**
* 执行Android命令,设置系统时间
* @param cmd 命令
*/
public static void execSuCmd(String cmd) {
Process process = null;
DataOutputStream os = null;
DataInputStream is = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
os.flush();
int aa = process.waitFor();
is = new DataInputStream(process.getInputStream());
byte[] buffer = new byte[is.available()];
is.read(buffer);
String out = new String(buffer);
} catch (Exception e) {
e.printStackTrace();
}
}
String curr_time = "092110202015.52"; // 传入时间格式
TimeUtils.execSuCmd("date " + curr_time);