public static void setSystemTime(String time) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
Date date = format.parse(time);
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
String formatDate;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
format = new SimpleDateFormat("MMddHHmmyyyy.ss");
formatDate = format.format(date);
os.writeBytes("date " + formatDate + " set \n");
os.writeBytes("busybox hwclock -w\n");
} else {
format = new SimpleDateFormat("yyyyMMdd.HHmmss");
formatDate = format.format(date);
os.writeBytes("/system/bin/date -s " + formatDate + "\n");
os.writeBytes("clock -w\n");
}
os.writeBytes("exit\n");
os.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
android 修改系统时间
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 问题描述 在Azure的 App Service / Function App 服务中,如果是在Windows系统...
- @TOC[Docker%E4%BF%AE%E6%94%B9Mysql%E5%AE%B9%E5%99%A8%E7%B...
- 前言 Google Play应用市场对于应用的targetSdkVersion有了更为严格的要求。从 2018 年...