I've noticed that the time in my emulator for android projects is wrong. Its one hour behind.
How do I go about changing the time and can I do it in eclipse?
Run>Debug Configurations/Run Configurations
Tab Target> Additional Emulator Command Line Options
-timezone America/New_York
use this command
C:\> adb shell
#date –- 2009-10-01 14:24:59
20070325.123456
#date –s 20070325.123456
I believe the emulator is set to the GMT timezone by default. You can specify the timezone for the emulator with the -timezone parameter.
https://developer.android.com/studio/run/emulator-commandline.html
If you want to change date & time, from running emulator window go to:
Apps -> Settings -> Date & Time -> Disable Automatic date & time -> Set date & Set time
If you want to change timezone, from running emulator window go to:
Apps -> Settings -> Date & Time -> Disable Automatic time zone -> Select time zone
If you use IntelliJ you can do that from Run/Edit Configurations window.
Go to Emulator tab and add this to "Additional command line options":
-timezone Europe/Helsinki
Android document gives this info:
-timezone Set the timezone for the emulated device to , instead of the host's timezone. must be specified in zoneinfo format. For example: "America/Los_Angeles"
"Europe/Paris"
Zoneinfo format is also known as tz database. So to find you specific timezone, you can use the Wikipedia list here:
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Increase emulator date by some certain hours, Perfectly working
Here i am increasing time by 4 hours.
adb root
adb shell "date date +09190400"
Month & Date : 0919(mmdd)
hours : 04
I have searched extensively, and it seems like the only option is to turn off the Auto-Set time in the emulator phone prefs, and manually set the timezone. I can't find any place to set emulator options from inside Eclipse/AVD Manager.
Set the time on the emulator via ADB:
Bash:
adb root
adb shell "date $(date +%m%d%H%M%G.%S)"
adb shell "am broadcast -a android.intent.action.TIME_SET"
Powershell:
$currentDate = Get-Date -Format "MMddHHmmyyyy.ss" # Android's preferred format
adb root
adb shell "date $currentDate"
adb shell "am broadcast -a android.intent.action.TIME_SET"
The am broadcast signal the clock to update in the status-bar, though its not needed according to my tests on emulator API-31.
The adb root lets following adb command execute with root-access, which is needed to set the date.
Thanks to RipTutorial
See also duplicate Stackoverflow with more info for special android-devices: Set date/time using ADB shell
refer to this page
http://ysl-paradise.blogspot.com/2008/09/android.html
in the comment part.
The question was 9 years ago, but these days (on a mac at least) you just change your mac's time in the OSX System Preferences Date & Time pane and it's immediately mirrored in the Android emulator.
Related
I'm running tests for my app, and I want to validate that it works in various time zones.
I'm trying solutions suggested here running adb shell setprop persist.sys.timezone "Pacific/Honolulu", but the timezone (and time) on emulator is not changing- can this work without restarting the device?
If you mean UI tests, I can not change android Date & Time settings on emulator via adb shell.
The only solution I found is to set the timezone during the creation of the emulator with -timezone option.
For example, you can create android emulator with a command like $ emulator #Nexus_5X_API_23 -timezone Europe/Paris.
See more emulator command line options here
A complete AOSP build lasts approximately 5 hours on my laptop. Instead of running make after each change (just want to test some ideas...) I read that it is possible to do mmm frameworks/opt/telephony (or any other module) and run make snod afterwards.
Unfortunately this does not work for me. The emulator simply hangs during the boot while displaying the big Android letters.
Can someone give me a hint what is going on there and how to fix the problem?
It is about Android 5 on x86_64.
After mmm frameworks/opt/telephony, try running:
adb root
adb remount
adb sync system
This should only sync files you've built. Once it finishes, restart the runtime:
adb shell stop
adb shell start
If I do a fresh boot on the emulated device, it gets the correct current time from the host OS; however, if I reload the device from a snapshot, it gets the time/date from the moment the snapshot was created (e.g. When I shut down the emulator). The time/date does not re-sync after any amount of time. The only way around it that I've found is to manually update the time after restoring from a snapshot.
The Android Virtual Device has default properties:
Target = Android 4.0.3 - API Level 15
CPU/ABI = ARM (armeabi-v7a)
SD Card = N/A
Snapshot = Enabled
Abstract LCD density = 240
Max VM application heap size = 48
Device RAM size = 512
I've tried the emulator on OS X Snow Leopard and Windows 7, both show the same problem. Is there any way to get the emulator to automatically sync time after restoring from snapshot?
I have been running into the same problem, and there does not seem to be a standard way of doing this. However, an emulator's date and time can be updated using the date command of the ADB shell, which can be used in conjunction with standard commands for displaying date and time on your OS to update the emulator date and time to the current date and time.
To set a date and time of the emulator, you need to execute the following command in your OS:
adb shell date -s YYYYmmdd.HHMMSS
where YYYYmmdd is the date and HHMMSS is the time.
Linux
Setting the emulator date and time to the current date and time is relatively straightforward from a UNIX-style shell, so the following command will work on Linux:
adb shell date -s `date +"%Y%m%d.%H%M%S"`
macOS
adb -e shell su root date `date +"%m%d%H%M%y"`
Windows
On Windows (which I am using), the easiest way to do it is through Windows PowerShell:
adb shell date -s $(get-date -format yyyyMMdd.HHmmss)
In Command Prompt, it is a bit more tricky because there is no way to specify a custom format to display date and time. The best way I found to get it in locale-independent format is by using the command wmic os get LocalDateTime (line 2). Its date-time format can be parsed to adapt to the format needed by the ADB shell: the symbols :~ can be used to print a substring of an environment variable contents, with the format %var:~<start-index>,<number-of-chars>%. We also need to ignore everything except line 2, so the full command that you need to run is as follows:
for /f "skip=1 delims=" %A in ('wmic os get localDateTime') do #for /f "delims=" %B in ("%A") do #cmd /v /c "set wmicdate=%B & adb shell date -s !wmicdate:~0,8!.!wmicdate:~8,6!"
For the curious: this first saves the date-time into the %wmicdate% variable and then passes it to ADB by parsing it appropriately. The ! are used instead of % to read the variable on-the-fly. This is all done in a child cmd process launched with the /v option that enables this on-the-fly variable reading.
EDIT: Fixed the command for macOS (thanks #user836003).
I opened a bug report.
I have the same kind of issues, and found out the hard way because my app that uses SSL, kept giving very weird errors. This was due to wrong date and time.
Apparently it's not yet reported.
On a newer Android emulator running version 6 API 23, the following powershell command worked for me.
Windows Powershell
adb shell date $(get-date -format MMddHHmmyyyy.ss)
On Android emulator version 7 API 24:
adb shell su root date $(get-date -format MMddHHmmyyyy.ss)
I have searched many times before for a solution to this and i searched again when i saw your question but i couldn't find anyone else even complaining about this except you and me, maybe others don't create apps that time is critical or they test on a real device.
Conclusion: no there is not fix, you have to set it manually or not use snapshots.
Voted Arthon's answer up.
It seems that the emulator get loose to sync when the host machine get sleep.
I'm, personally, using following program for this.
public class AdbShellDateNow {
public static void main(final String[] args)
throws java.io.IOException, InterruptedException {
final long now = System.currentTimeMillis() / 1000L;
final ProcessBuilder builder =
new ProcessBuilder("adb", "shell", "date", Long.toString(now));
builder.redirectErrorStream(true);
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
final Process process = builder.start();
process.waitFor();
}
}
This one from macOS works best for me since it takes the time of the host to sync:
adb shell su root date -u #$(date -u +%s)
have tried to change the timezon in android-emulator but it doesn't work. I write the -timezone option in eclipse menu: Window - Preferences - Android - Launch - Default Emulator options:
-timezone Europe/Stockholm
I found the timezone info here.
In stockholm we add one hour to the british time. If my computer clock is e.g. 22.19 I also want the time in the android emulator to be 22.19. But it always show 21.19. How shall I give the -timezone arg to the emulator from inside eclipse so it works. I use winXp and Eclipse 3.5. And I have always restarted the emulator after each change of timezone.
emulator -timezone Europe/Stockholm
Should work (on Linux). No quotes needed.
Try this is an adb shell:
# date
Thu Dec 2 00:04:02 CET 2010
# date -u
Wed Dec 1 23:04:05 GMT 2010
Yes it works fine!
Firstly you have to shutdown you emulator.
Then in the menu clic "RUN" and then Run Configurations...
On the left, please select "Android Application" -> [name of your application]
On the right, clic the "target" tab, then scroll down and look for the "Additional Emulator Command Line Option" textbox. In that box you can specify:
-timezone [desired timezone]
Example:
-timezone Europe/Stockholm //
-timezone America/Argentina/Mendoza //
etc...
Duplicate:
https://stackoverflow.com/a/2993414/980687
Run>Debug Configurations/Run Configurations
Tab Target> Additional Emulator Command Line Options
-timezone America/New_York
For automated testing (using Hudson) I have a script that generates a bunch of emulators for many combinations of Android OS version, screen resolution, screen density and language.
This works fine, except for the language part.
I need to find a way to change the Android system locale automatically. Here's some approaches I can think of, in order of preference:
Extracting/editing/repacking a QEMU image directly before starting the emulator
Running some sort of system-locale-changing APK on the emulator after startup
Changing the locale settings on the emulator filesystem after startup
Changing the locale settings in some SQLite DB on the emulator after startup
Running a key sequence (via the emulator's telnet interface) that would open the settings app and change the locale
Manually starting the emulator for each platform version, changing the locale by hand in the settings, saving it and archiving the images for later deployment
Any ideas whether this can be done, either via the above methods or otherwise?
Do you know where locale settings are persisted to/read from by the system?
Solution:
Thanks to dtmilano's info about the relevant properties, and some further investigation on my part, I came up with a solution even better and simpler than all the ideas above!
I have updated his answer below with the details.
Personally I think the simplest way is to start the emulator, probably a clean instance unless you are running integration tests that depends on other applications and then change locale using adb:
$ adb shell '
setprop persist.sys.language en;
setprop persist.sys.country GB;
stop;
sleep 5;
start'
or whatever locale you want to set.
To verify that your change was successful just use
$ adb shell 'getprop persist.sys.language'
You may also want to run emulators on know ports, check my answer in this thread.
Note that you can also set system properties directly when starting the emulator:
emulator -avd my_avd -prop persist.sys.language=en -prop persist.sys.country=GB
This way, you can create a plain old emulator of any type then start it up immediately using the locale of your choice, without first having to make any modifications to the emulator images.
This locale will persist for future runs of the emulator, though of course you can always change it again at startup or during runtime.
Accepted answer doesn't work anymore. persist.sys.language and persist.sys.country are gone from emulator properties.
My solution is to use preinstalled on android emulator "Custom locale" application. Simply send intent with extra language parameter to it as below:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE EN
More information here - prepare android emulator for UI test automation.
UPDATE: based on comment from Jonas Alves the following command works on API 28+:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE "en_US" com.android.customlocale2
Seems that Android emulator now supports setting the locale when starting it:
emulator -avd <avd-name> -change-locale fr-CA
Source - https://androidstudio.googleblog.com/2019/09/emulator-29112-stable.html