恢复快照后仿真Android设备不会重新同步时间/日期快照、日期、时间、设备

2023-09-04 10:16:17 作者:眉间清风

如果我做的模拟设备上的一个新的引导,它会从主机操作系统的当前时间;不过,如果我重新加载该设备从一个快照,它得到的时间/日期从创建快照时(例如当我关闭仿真器)。的任何时间量之后的时间/日期不重新同步。围绕它的唯一的方式,我发现是从快照中恢复后手动更新的时间。

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.

Android的虚拟设备都有默认属性:

The Android Virtual Device has default properties:

目标=安卓4.0.3 - API等级15

Target = Android 4.0.3 - API Level 15

CPU / ABI = ARM(armeabi-V7A)

CPU/ABI = ARM (armeabi-v7a)

SD卡= N / A

SD Card = N/A

快照=启用

摘要LCD密度= 240

Abstract LCD density = 240

最大虚拟机应用程序堆大小= 48

Max VM application heap size = 48

设备RAM大小= 512

Device RAM size = 512

我已经试过在OS X雪豹和Windows 7的模拟器,都显示了同样的问题。有没有什么办法让模拟器从快照中恢复后自动同步的时间?

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

其中YYYYMMDD是日期,HHMMSS是时候了。

where YYYYmmdd is the date and HHMMSS is the time.

设置仿真器的日期和时间设置为当前日期和时间是从UNIX风格的外壳相对简单,所以下面的命令将工作在Linux和MacOS:

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 and MacOS:

adb shell date -s `date +"%Y%m%d.%H%M%S"`

的Windows

在Windows(我现在用的),做它是通过Windows PowerShell中最简单的方法:

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)

在命令提示符,它是有点更棘手,因为没有办法来指定自定义格式来显示日期和时间。我发现得到它的语言环境无关的格式,最好的办法是使用命令 WMIC操作系统获取LocalDateTime (2号线)。它的日期时间格式可以解析,以适应需要亚行的shell的格式:符号:〜可用于打印的环境变量内容子串,用格式%VAR:〜<启动索引>,<数的,字符>%。我们还需要忽略一切,除了2号线,这样就需要运行完整的命令如下:

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!"

有关的好奇:这首先保存日期,时间到%wmicdate%变量,然后通过适当地解析它传递给亚行。该来代替来的