I'm in the process of creating an android app that makes extensive use of the time & date functions in android, including many uses of AlarmManager. For testing though, it's 开发者_如何转开发a big pain to change windows' system clock just to test some functionality.
Is there a way to change the clock on he emulator so that it thinks it's on a different day?
Just do it as you would in a normal handset:
Settings -> Date & Time, then disable Automatic and set the Date and Time
Now I found a solution, which makes it easier to reset the simulator to a specific time without doing this manually every time.
- Start a simulator, where you can get root access (simulator without Play Store)
- Open Android Adb Command Prompt
- Get root access with
adb root
- Connect to the shell of the emulator with
adb -e shell
or to a specific emulator withadb -s emulator-5553 shell
- Change the date and broadcast it immediately with e.g.
date 112509412020.00 ; am broadcast -a android.intent.action.TIME_SET
(time format ist MMDDhhmmYYYY.00) - You should see the new time in the simulator and get this on the shell Broadcast completed: result=0
But you still have to call the last command every time to reset it ...
精彩评论