简体   繁体   English

更改root设备上的日期(Android M)

[英]Change date on rooted device (Android M)

I am developing a widget for my application, which can change the system time of the device. 我正在为我的应用程序开发一个小部件,它可以改变设备的系统时间。 I know, that the device has to be rooted, that should not be the problem. 我知道,设备必须扎根,这应该不是问题。
You can add 2, 15 or 31 days to the system time. 您可以在系统时间中添加2天,15天或31天。

So far I was working with this method and it was working fine. 到目前为止,我正在使用这种方法,它工作正常。

Now, that Android M will come out soon, I tested my application on the Android M Preview 3 and I got the problem, that the above code only displays the date change on my widget but it won't change it on the device. 现在,Android M即将推出,我在Android M Preview 3上测试了我的应用程序,我遇到了问题,上面的代码只显示我的小部件上的日期更改,但它不会在设备上更改它。

I tested a few formats in the adb shell and had a solution, that nearly fit what I want. 我在adb shell中测试了一些格式并且有一个几乎符合我想要的解决方案。

    command = "date -u "+month+day+hour+minute+year+"."+second+"\n";

Now, the date of the device is changed BUT when i add 2 days it will also add 2 hours to the date. 现在,设备的日期已更改但是当我添加2天时,它还将添加2小时的日期。 For example: 10.09.2015 09:43 -> 12.09.2015 11:43 例如:10.09.2015 09:43 - > 12.09.2015 11:43
And if I check "Automatic date and time" in the settings after changing the date a couple of times, the device changes to a random date a few days in the past, which won't be reset at all until i restart the device. 如果我在更改日期后多次检查设置中的“自动日期和时间”,则设备会在过去几天内更改为随机日期,在重新启动设备之前,该日期将不会重置。

Any thoughts on this? 有什么想法吗?

You need to use this command/format since Android M ships with the toybox date command and not the toolbox custom date command from L 您需要使用此命令/格式,因为Android M附带了toybox date命令,而不是来自L的工具箱自定义日期命令

adb shell date $(date +%m%d%H%M%Y)

Old format for L was L的旧格式是

adb shell date -s $(date +%Y%m%d.%H%M%S)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 appium 或 adb 更改 root android 设备的 IMEI 号码? - How to change the IMEI number of a rooted android device via appium or adb? 在已root用户的Android设备中复制系统文件 - Copy system files in rooted android device 在root用户设备上设置鼠标位置 - set mouse position on rooted android device 如何以编程方式在Android植根设备中将.raw文件转换为图像文件 - How to convert .raw file to image file in android rooted device programmatically 如何在Rooted android设备中使用shell命令读取SMS? - How to read the SMS using shell commands In Rooted android Device? 以编程方式在Android设备上创建Google帐户(非root用户设备) - Creating a google account on android programatically (non-rooted device) 在根目录下的Android设备中访问和操作外部USB存储设备上的文件和目录 - Access and manipulate files and directories on an external USB storage in a rooted Android device Android:检索其他应用程序(root设备)的共享首选项 - Android: Retrieving shared preferences of other application (rooted device) 通过Google TV(Android非根设备)从端口查找pid - find pid from port over Google TV (Android non-rooted device) 如何在包含 magisk 应用程序的根设备中限制我的 android 应用程序? - How to restrict my android app in rooted device which contain magisk app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM