3

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.

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.

I tested a few formats in the adb shell and had a solution, that nearly fit what I want.

    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. For example: 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?

Community
  • 1
  • 1
Felix Plaumann
  • 255
  • 1
  • 2
  • 8

1 Answers1

4

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

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

Old format for L was

adb shell date -s $(date +%Y%m%d.%H%M%S)
David
  • 3,324
  • 2
  • 27
  • 31
  • 1
    Works for me! The status bar clock doesn't seem to change but the system time does – drewi Apr 14 '16 at 21:20
  • 1
    This format is correct and it kind of works in that when you go into Settings -> Date & Time you'll see the "Set time" correctly matching your new time, but I found that multitasking stops working (you can't switch apps, nothing happens when you touch the button) and the widget time doesn't update. If you launch the Clock app it'll show the new time, but it won't update. You can't close the Clock app to try and re-launch, and it doesn't update to the new time (I assume the Clock app shows the current time as the time changes naturally) and seems stuck. – dubmojo Jul 30 '16 at 00:04