需先Root後才可使用
public static boolean changeSystemTime(String datetime) {
String[] times = datetime.split(" ");
if (times.length == 2) {
return changeSystemTime(times[0].replace("-", ""),
times[1].replace(":", ""));
}
return false;
}
private static boolean changeSystemTime(String date, String time) {
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
String command = "date -s " + date + "." + time + "\n";
os.writeBytes(command);
os.flush();
os.writeBytes("exit\n");
os.flush();
process.waitFor();
return true;
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
沒有留言:
張貼留言