[英]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.