1

I am working on test cases part, I wanted to check whether I am getting proper time from server even after changing time inside android device. For this I am using adb shell commands to overwrite date and time but this is not reflecting.

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
int date1 = calendar.get(Calendar.DATE);
getInstrumentation().getUiAutomation().executeShellCommand("date -s 07171010.00");
getInstrumentation().getUiAutomation().executeShellCommand("am broadcast -a android.intent.action.TIME_SET");
calendar.setTimeInMillis(System.currentTimeMillis());
int date2 = calendar.get(Calendar.DATE);
itsmysterybox
  • 2,748
  • 3
  • 21
  • 26
skyshine
  • 2,767
  • 7
  • 44
  • 84

1 Answers1

1

From my experience, you have to add a sleep after invoking any ADB command in order to take effect.
See for example the comments here : https://stackoverflow.com/a/50859369/10472007 or here https://stackoverflow.com/a/37737047/10472007

A quote from the last one :

The command will not be visible immediately on the device because it doesn't trigger any time change broadcast, But it will be visible within a minute.

Check it out !

Else check the command syntax depending your device/OS version as suggested in the page given by Alex P.

MrAurelien
  • 358
  • 2
  • 11