命令行启动虚拟机

当我们下载安装好,可以通过命令行运行指定名字模拟器

D:\ProgramFiles\Genymobile\Genymotion\player  --vm-name "Samsung Galaxy S3 - 4.1.1 - API 16 - 720x1280"

:: 列出虚拟设备
Genymotion installer path>\genyshell -c "devices list" :: Genymotion Shell > devices list
::
:: |----------------------------------------------------------------------|
:: | No Genymotion virtual device running found |
:: | Please, run at least one Genymotion virtual device to use this shell |
:: |----------------------------------------------------------------------|
::
:: Available devices:
::
:: Id | Select | Status | Type | IP Address | Name
:: ----+--------+---------------+----------+-----------------+---------------
:: 0 | | Off | virtual | 0.0.0.0 | Google Nexus 7 - 5.1.0 - API 22 - 800x1280
:: 1 | | Off | virtual | 0.0.0.0 | Google Nexus S - 2.3.7 - API 10 - 480x800
:: 2 | | Off | virtual | 192.168.56.101 | Samsung Galaxy Note 2 - 4.2.2 - API 17 - 720x1280
:: 3 | | Off | virtual | 0.0.0.0 | Samsung Galaxy S4 - 4.3 - API 18 - 1080x1920 :: 启动某虚拟设备 <VM id | VM name>
<Genymotion installer path>\player --vm-name "<virtual device name>"

Since Genymotion 2.5.0
gmtool admin create "Google Nexus 5 - 4.4.4 - API 19 - 1080x1920" myNexus
gmtool admin start myNexus

当使用genymotion的控制台shell时,一些命令在免费版本不可用,同样的界面上按钮也不可用。

其实,官方文档就有:https://www.genymotion.com/#!/support?chapter=start-virtual-devices-command-prompt

另外可以参考:How to start Genymotion device with shell command?

VirtualBox DHCP server has not assigned an IP address to virtual

D:\ProgramFiles\Oracle\VirtualBox>VBoxManage list dhcpservers
NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #10
IP: 169.254.238.100
NetworkMask: 255.255.0.0
lowerIPAddress: 169.254.238.101
upperIPAddress: 169.254.238.254
Enabled: Yes NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #11
IP: 169.254.189.100
NetworkMask: 255.255.0.0
lowerIPAddress: 169.254.189.101
upperIPAddress: 169.254.189.254
Enabled: Yes NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #9
IP: 169.254.190.100
NetworkMask: 255.255.0.0
lowerIPAddress: 169.254.190.101
upperIPAddress: 169.254.190.254
Enabled: Yes NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter
IP: 192.168.56.100
NetworkMask: 255.255.255.0
lowerIPAddress: 192.168.56.101
upperIPAddress: 192.168.56.254
Enabled: Yes NetworkName: NatNetwork
IP: 10.0.2.3
NetworkMask: 255.255.255.0
lowerIPAddress: 10.0.2.4
upperIPAddress: 10.0.2.254
Enabled: Yes

VBoxManage list dhcpservers

先禁用virtual box 的dhcp功能 VBoxManage dhcpserver remove --netname "<name>"。

D:\ProgramFiles\Oracle\VirtualBox>VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-Vi
rtualBox Host-Only Ethernet Adapter #10" D:\ProgramFiles\Oracle\VirtualBox>VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-Vi
rtualBox Host-Only Ethernet Adapter #11" D:\ProgramFiles\Oracle\VirtualBox>VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-Vi
rtualBox Host-Only Ethernet Adapter #9" D:\ProgramFiles\Oracle\VirtualBox>VBoxManage list dhcpservers
NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter
IP: 192.168.56.100
NetworkMask: 255.255.255.0
lowerIPAddress: 192.168.56.101
upperIPAddress: 192.168.56.254
Enabled: Yes NetworkName: NatNetwork
IP: 10.0.2.3
NetworkMask: 255.255.255.0
lowerIPAddress: 10.0.2.4
upperIPAddress: 10.0.2.254
Enabled: Yes

VirtualBox Host-Only ethernet Adapter

VirtualBox安装后会在Windows分配一个网卡——虚拟网卡而已,在控制面板\网络和 Internet\网络连接中可以看到 VirtualBox Host-Only Network,这个网卡的IP一般是

以太网适配器VirtualBox Host-Only Network:

连接特定的DNS 后缀. . . . . . . :

本地链接IPv6 地址. . . . . . . . : fe80::9849:c1ab:2f1b:f7f2%18

IPv4 地址. . . . . . . . . . . . : 192.168.56.1

子网掩码  . . . . . . . . . . . . : 255.255.255.0

默认网关. . . . . . . . . . . . . :

但是这里,有VirtualBox Host-Only Ethernet Adapter适配器,但是ipconfig没有看到地址。

无参ipconfig调用,默认情况下,仅显示绑定到 TCP/IP 的每个适配器的 IP 地址、子网掩码和默认网关。

D:\ProgramFiles\Oracle\VirtualBox>ipconfig

Windows IP 配置

以太网适配器 以太网:

媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . : 无线局域网适配器 本地连接* 2: 媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . : 以太网适配器 以太网 2: 连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::4521:6580:93a9:16dc%43
IPv4 地址 . . . . . . . . . . . . : 192.168.56.1
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 无线局域网适配器 WLAN: 连接特定的 DNS 后缀 . . . . . . . : lan
本地链接 IPv6 地址. . . . . . . . : fe80::fc82:67dc:9ef4:c27f%17
IPv4 地址 . . . . . . . . . . . . : 192.168.100.105
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 192.168.100.1 隧道适配器 isatap.lan: 媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . : lan 隧道适配器 Teredo Tunneling Pseudo-Interface: 媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . : 隧道适配器 isatap.{BB4C487E-1A6F-FFFF-BBBD-FEB6DFFFFFCF}: 媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . : 带参数ipconfig /all ... 显示详细信息 D:\ProgramFiles\Oracle\VirtualBox>ipconfig /all Windows IP 配置 主机名 . . . . . . . . . . . . . : DESKTOP-IRTI28J
主 DNS 后缀 . . . . . . . . . . . :
节点类型 . . . . . . . . . . . . : 混合
IP 路由已启用 . . . . . . . . . . : 否
WINS 代理已启用 . . . . . . . . . : 否
DNS 后缀搜索列表 . . . . . . . . : lan 无线局域网适配器 本地连接* 2: 媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
描述. . . . . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
物理地址. . . . . . . . . . . . . : FF-FF-FF-FF-BF-63
DHCP 已启用 . . . . . . . . . . . : 是
自动配置已启用. . . . . . . . . . : 是 以太网适配器 以太网 2: 连接特定的 DNS 后缀 . . . . . . . :
描述. . . . . . . . . . . . . . . : VirtualBox Host-Only Ethernet Adapter
物理地址. . . . . . . . . . . . . : 08-22-27-52-94-FE
DHCP 已启用 . . . . . . . . . . . : 是
自动配置已启用. . . . . . . . . . : 是
本地链接 IPv6 地址. . . . . . . . : fe80::4521:6580:93a9:16dc%43(首选)
IPv4 地址 . . . . . . . . . . . . : 192.168.56.1(首选)
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . :
DHCPv6 IAID . . . . . . . . . . . : 721944615
DHCPv6 客户端 DUID . . . . . . . : 00-01-00-01-1D-51-2B-73-00-90-F5-F6-AE-FD
DNS 服务器 . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
TCPIP 上的 NetBIOS . . . . . . . : 已启用 无线局域网适配器 WLAN: 连接特定的 DNS 后缀 . . . . . . . : lan
描述. . . . . . . . . . . . . . . : Realtek RTL8723AE Wireless LAN 802.11n PCI-E NIC
物理地址. . . . . . . . . . . . . : FF-E3-FF-FF-FF-FF
DHCP 已启用 . . . . . . . . . . . : 是
自动配置已启用. . . . . . . . . . : 是
本地链接 IPv6 地址. . . . . . . . : fe80::fc82:67dc:9ef4:c27f%17(首选)
IPv4 地址 . . . . . . . . . . . . : 192.168.100.105(首选)
子网掩码 . . . . . . . . . . . . : 255.255.255.0
获得租约的时间 . . . . . . . . . : 2015年11月9日 21:44:07
租约过期的时间 . . . . . . . . . : 2015年11月10日 21:59:41
默认网关. . . . . . . . . . . . . : 192.168.100.1
DHCP 服务器 . . . . . . . . . . . : 192.168.100.1
DHCPv6 IAID . . . . . . . . . . . : 103342919
DHCPv6 客户端 DUID . . . . . . . : 00-01-01-11-1D-51-2B-73-00-90-F5-F6-AE-FD
DNS 服务器 . . . . . . . . . . . : 192.168.100.1
TCPIP 上的 NetBIOS . . . . . . . : 已启用

ipconfig

虽然早就看到这个问题的解决有一个是取消windows的hy设置,但是总以为分配ip和这个无关。最后不得不关掉这个设置重启机器,确实可行,机器为win10。

安装好VirtualBox出现Host-Only,启动genymotion.exe出现Host-Only #2,启动一个虚拟机出现Host-Only #3

C:\Program Files\Oracle\VirtualBox>VBoxManage list dhcpservers
NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter
IP: 0.0.0.0
NetworkMask: 0.0.0.0
lowerIPAddress: 0.0.0.0
upperIPAddress: 0.0.0.0
Enabled: No NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #2
IP: 192.168.191.100
NetworkMask: 15.0.0.0
lowerIPAddress: 192.168.191.101
upperIPAddress: 192.168.191.254
Enabled: Yes NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #3
IP: 192.168.43.100
NetworkMask: 15.0.0.0
lowerIPAddress: 192.168.43.101
upperIPAddress: 192.168.43.254
Enabled: Yes

VBoxManage list dhcpservers

功能限制解除之一

Genymotion Shell > phone call 110
No valid license found. This command is not available with the Free version.
You can purchase a license on https://shop.genymotion.com/ to use this command.
>>> Failed

 

命令行工具crack要点:

搜索字符串,nop前一个跳转,尝试命令phone call 110,patch修改OK。

 

和虚拟设备交互

Interacting with virtual devices

To modify sensor statuses and values of a virtual device, use the commands listed below:

  • devices list
    Lists available virtual devices and provides details such as current status, IP address and name.
  • devices refresh
    Refreshes the virtual device list.
  • devices select
    Selects a virtual device. Add the ID of the virtual device you wish to select (as displayed in the device list).
  • devices ping
    Sends a ping message to check that the virtual device is responding.
  • devices factoryreset
    Resets the virtual device to factory state. Add the ID of the device you wish to reset (as displayed in the device list). Adding the keyword force at the end skips the warning message about data loss.
  • battery getmode
    Returns the current battery mode of the selected virtual device.
  • battery setmode
    Sets the battery mode of the selected virtual device. The mode can be:
    • host: the virtual battery values reflect the host battery values (if any);
    • manual: the virtual battery charge level and state of charge can be manually set.
  • battery getlevel
    Returns the current battery charge level of the selected virtual device. If the battery mode is "host", the returned value is the host value.
  • battery setlevel
    Sets the battery charge level of the selected virtual device. The value must range from 0% to 100%. This command forces the activation of the manual mode.
  • battery getstatus
    Returns the current battery state of charge of the selected virtual device.
  • battery setstatus
    Sets the battery connection status of the selected virtual device. Values can be:
    • discharging: simulates that the power supply is unplugged and the battery is discharging.
      The value ranges from 0% to 100%.
    • charging: simulates that the power supply is plugged in and the battery is charging.
      The value ranges from 0% to 100%.
    • notcharging: simulates that the power supply has just been unplugged and the battery is not discharging yet.
      The value ranges from 0% to 100%.
    • full: simulates that the battery is fully charged.
  • gps getstatus
    Returns the status of the GPS signal reception.
  • gps setstatus
    Sets the activation status of the GPS signal reception. Values can be:
    • enabled: the GPS signal reception is enabled;
    • disabled: the GPS signal reception is disabled.
  • gps getlatitude
    Returns the current latitude value (if the GPS is activated and a latitude value is set) or 0.
  • gps setlatitude
    Sets the latitude value (and forces the activation of the GPS if deactivated). The value must range from -90° to 90°.
  • gps getlongitude
    Returns the current longitude value (if the GPS is activated and a longitude value is set) or 0.
  • gps setlongitude
    Sets the longitude value (and forces the activation of the GPS if deactivated). The value must range from -180° to 180°.
  • gps getaltitude
    Returns the current altitude value (if the GPS is activated and an altitude value is set) or 0.
  • gps setaltitude
    Sets the altitude value (and forces the activation of the GPS if deactivated). The value must range from -20m to 10000m.
  • gps getaccuracy
    Returns the current accuracy value (if the GPS is activated and an accuracy value is set) or 0.
  • gps setaccuracy
    Set the accuracy value (and forces the activation of the GPS if deactivated). The value must range from 0m to 200m.
  • gps getbearing
    Returns the current bearing value (if the GPS is activated and a bearing value is set) or 0.
  • gps setbearing
    Sets the bearing value (and forces the activation of the GPS if deactivated). The value must range from 0° to 359,99°.
  • rotation setangle
    Sets the rotation angle value of the virtual device. The value must range from 0° to 359°.
  • android version
    Returns the Android version of the selected virtual device.
  • android getandroidid
    Returns the Android ID number of the selected virtual device.

    This is only possible with an Indie or a Business license.

  • android setandroidid
    Sets the Android ID number of the selected virtual device.
    Values can be:
    • random: a random Android ID number is generated;
    • custom: you must enter a value containing 16 hexadecimal digits.

    This is only possible with an Indie or a Business license.

    If several users exist on the Android system, the Android ID can only be set for the first user.

  • android getdeviceid
    Returns the device ID (IMEI/MEID) number of the selected virtual device.

    This is only possible with an Indie or a Business license.

  • android setdeviceid
    Sets the device ID (IMEI/MEID) number of the selected virtual device.
    Values can be:
    • none: no device ID number is generated.
    • random: a random device ID number is generated.
    • custom: you must enter a value containing alphanumeric characters, dots, dashes and/or underscores.

    This is only possible with an Indie or a Business license.

  • network getprofile
    Returns the current network profile of the selected virtual device.
  • network setprofile
    Sets the network profile of the selected virtual device. Values can be:
    • none: no network profile is enabled.
    • no-data: no network connection is simulated.
    • gprs: a GPRS network connection is simulated.
    • edge: an Edge network connection is simulated.
    • 3g: a 3G network connection is simulated.
    • 4g: a 4G network connection is simulated.
    • 4g-high-losses: a 4G network connection with packet loss set to 10% is simulated.
    • 4g-bad-dns: a 4G network connection with a DNS delay set to 3000ms is simulated.
    • wifi: a Wi-Fi network connection is simulated.

电话功能

    • phone call <phone_number> 模拟某号码的来电
      simulates an incoming phone call from a given phone number.
    • phone sms <phone_number> <message> 模拟某号码的短信
      simulates an incoming text message from a given phone number.
    • phone baseband <command> 模拟基带命令
      sends commands directly to the baseband. This command has been implemented in order to ease script creation. For more information on the phone baseband command and its capabilities, please refer to Baseband commands(或本页连接).

Baseband commands

The phone baseband commands send raw data directly to the baseband. In this section, you will find all commands available in Genymotion Shell to directly interact with the baseband.

Commands below return results in your logcat.

  • gsm list
    lists all incoming and outgoing phone calls and their state.
  • gsm call <phone_number>
    simulates a new incoming call from a given phone number.
  • gsm busy <remote_number>
    hangs up an outgoing call (performed from the integrated Dialer application) and reports the remote phone as busy.
  • gsm hold <remote_number>
    simulates that an incoming or outgoing phone call (performed from the integrated Dialer application) is put on hold.
  • gsm accept <remote_number>
    simulates that the outgoing phone call (performed from the integrated Dialer application) is answered.
  • gsm cancel <phone_number>
    simulates that an incoming or outgoing phone call is hung up.
  • gsm data
    modifies data connection state. Values can be:
    • unregistered or off: no network available;
    • home or on: on local network, non-roaming;
    • roaming: on roaming network;
    • searching: searching networks;
    • denied: emergency calls only.
  • gsm voice
    modifies voice connection state. Values can be:
    • unregistered or off: no network available;
    • home or on: on local network, non-roaming;
    • roaming: on roaming network;
    • searching: searching networks;
    • denied: emergency calls only.
  • gsm status
    displays the current status of the GSM emulation.
  • gsm signal <rssi> <ber> <rs_snr>
    changes the reported strength and error rate on next (15s) update.
    • rssi: the value must range from 0 to 31. Returns 99 if the value is unknown.
    • ber: the value must range from 0% to 7%. Returns 99 if the value is unknown.
    • rs_snr: the value must range from -200 to 300.
  • cdma ssource <ssource>
    sets the current CDMA subscription source. Values can be:
    • nv : the subscription is read from non-volatile RAM;
    • ruim: the subscription is read from RUIM.
  • cdma prl_version <version>
    dumps the current PRL version.
  • sms send <phone_number> <message>
    simulates an incoming text message from a given phone number.
  • sms pdu <hexstring>
    simulates a new incoming text message defined in the PDU format.

adb命令

where-to-find-info-on-androids-service-call-shell-command

检查服务是否存在
$ adb shell service check phone #< ServiceName >
Service phone: found

通过adb 命令拨打电话
adb shell service call phone 2 s16 "10086" #< PhoneNumber >
adb shell service call phone 5 s16

adb shell service call isms 5 s16 "PhoneNumber" i32 0 i32 0 s16 "BodyText"

通过adb 命令发送短信,需要两步
adb shell am start -a android.intent.action.SENDTO -d sms:10086(发送目的号码) --es sms_body "hello"(短信内容) --ez exit_on_sent true
adb shell input keyevent 66 // 模拟发送按键
MyApp:V
adb shell am start -a android.provider.Telephony.SMS_RECEIVED

模拟器电量驱动

lgocat一直报告错误:12-01 14:50:50.566: E/Genymotion(323): Could not open '/sys/class/power_supply/genymotion_fake_path/present'

控制台1或其他 控制台2:使用watchprops命令监控变化
  C:\Users\fangss>adb shell
root@android:/ # watchprops
watchprops
root@android:/
# setprop genyd.battery.mode host
setprop genyd.battery.mode host
1448952348 genyd.battery.mode =
'host'
1448952350 genyd.battery.mode = 'manual'
1448952350 genyd.battery.level = '50000000'
1448952350 genyd.battery.full = '50000000'
1448952350 genyd.battery.capacity = '100'
1448952350 genyd.battery.status = 'Not charging'
1448952350 genyd.ac.online = '1'
从界面上的电池控制对话框关闭 1448952364 genyd.battery.mode =
'auto'
1448952365 genyd.battery.mode = 'manual'
1448952365 genyd.battery.level = '50000000'
1448952365 genyd.battery.full = '50000000'
1448952365 genyd.battery.capacity = '100'
1448952365 genyd.battery.status = 'Not charging'
1448952365 genyd.ac.online = '1'

1、battery getmode:Return the current battery mode of the selected virtual device. (返回当前的电池模式选择的虚拟设备。)The mode can only be(该模式仅限于):

host:The virtual battery reflect the host battery (if exists) (以虚拟电池显示为主机电池——如果存在)
manual:In this mode, you can set the level and status battery values(在该模式下,可设置电池等级和电池状态)
2、battery setmode:Set the battery mode.(设置电池模式。)The mode can only be(该模式仅限于):          
host:The virtual battery reflect the host battery (if exists) (以虚拟电池显示为主机电池——如果存在)
 
manual:In this mode, you can set the level and status battery values(在该模式下,可设置电池等级和电池状态)
3、battery getlevel:Return the current battery amount of power.(返回当前电池的电量。) The value can only be between 0% and 100%.(只能在0%到100%之间设置);
If the battery mode is "host", the returned value is the host value.(如果电池模式已设置为“主机电池”,返回的值便是该主机电池的值。)
4、battery setlevel:Set the current battery amount of power.(设置当前电池的电量。) The value can only be between 0% and 100%.(只能在0%到100%之间设置);
Set the battery level force the "manual" mode(设置电池级别为强制“手动”模式):if the last mode was "host", then it's turned to "manual"(如果之前模式为“主机电池”,即可仅有设定更换为“手动模式”;         
5、battery getstatus:Return the current battery status.(返回当前电池状态。)There are 4 possible status(应该有4个状态):           
Discharging(放电):The power supply is disconnected and the battery is discharging(断开电源和电池放电);
Charging(充电):The power supply is connected and the battery is charging(电源连接和电池充电);
Full(充满):The battery is full.(电池充满。);
Unknown(未知):Sometimes, the battery status cannot be established, it happens when there is no host battery.(有时,如果显示为电池状态无法建立,一般是在没有设置主机电池的情况下。)
6、battery setstatus:Set the current battery status(设置当前电池状态). There are 4 possible status(应该有4个状态):          
Discharging(放电):The power supply is disconnected and the battery is discharging. (断开电源和电池放电);            
Charging(充电): The power supply is connected and the battery is charging. (电源连接和电池充电);            
Full(充满):The battery is full. (电源连接和电池充电);            
Unknown(未知):Sometimes, the battery status cannot be established, it happens when there is no host battery. (有时,如果显示为电池状态无法建立,一般是在没有设置主机电池的情况下。)
 

Andy模拟器

出来有一段时间了,现在流畅度和兼容度未知,地址http://www.andyroid.net

Try Andy for android and see what happens.

官方SDK自带模拟器

有新进展
 

微软发布的Android模拟器

出示

模拟器时间/时区

取得系统时间

要得到目前的时间,这个倒是很容易,就是 System.currentTimeMillis()。不过要注意的是,这个函式传回的是 UTC (GMT) 这个时区的时间,像台湾所在的时区是 UTC+8,你得将这个函式所传回的值再加 8 个小时,才是你要的答案。实际上,当然不用自己加,你可以借用 Calendar 这个类别来帮你。

更改系统时间

要更改系统的时间,这可就难倒我了。在 m5 SDK 上,用 SystemClock.setCurrentTimeMillis(),虽然会有警告讯息,不过系统时间还是会被更改。到了 v0.9 SDK,这招就没效了。扫过 Android 的原始程式,他们的确是用这个函式在更改系统时间。可是在我的程式里,不管我加了那些 permission,都是给我个 Permission denied 错误。最好,只好在 这里发文问了这个问题,有个应该是 Google 的工程师,给了下面这个答案。

User apps cannot set the time. Only the system processes can. This is for security, but also because it won't have much effect--the time is reset from the radio via network time.

看了,要在 application 这一层更改系统时间,应该是没解了。如果有人知道其他答案的,帮忙解答一下。

取得与更改系统时区

用 TimeZone.getDefault() 就可以取得当前的时区,如果你没有特别设定的话,那你取到的,都是 GMT 这个时区。看起来,至少在 Windows 平台上, Android Emulator 还是不会正确决定当前的时区。目前我知道的唯一方法就是,在启动 Emulator 的参数上,加上 -timezone "Asia/Taipei"。透过启动 Emulator 的参数可以更改时区,那可以透过 API 来更改系统时区吗?我试过 TimeZone.setDefault(TimeZone.getTimeZone("Asia/Taipei")),也用过 System.setProperty("user.timezone", "Asia/Taipei"),没一个有效。所以看起来,也暂时无解。有谁知道如何透过 API 更改系统时区?

设置系统的时区配置

cat /data/property/persist.sys.timezone //查看当前时区配置文件
setprop persist.sys.timezone GMT        //修改属性 
2、开始设置修改当前系统时间

date -s "yyyymmdd.[[[hh]mm]ss]"  或System/bin/date -s "yyyymmdd.[[[hh]mm]ss]"

3、查看是否生效

date

二、用代码实现修改android 系统时间的方法

public void testDate(){
try {
Process process = Runtime.getRuntime().exec("su");
String datetime="20131023.112800"; //测试的设置的时间【时间格式 yyyyMMdd.HHmmss】
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("setprop persist.sys.timezone GMT\n");
os.writeBytes("/system/bin/date -s "+datetime+"\n");
os.writeBytes("clock -w\n");
os.writeBytes("exit\n");
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
}

android默认系统日期、时间、时区更改

做android平台,经常会遇到产品需要更改系统默认时区日期时间的问题。android更改时区相对比较容易实现,网上也有很多资料,直接设置一个属性即可,例如设置上海东八区,persist.sys.timezone=Asia/Shanghai。但是如何实现更改默认系统时间呢?

在android中,Linux内核中、rtc时钟,默认的起始日期都是1970年1月1日,那么如何把默认日期指到2012-01-01呢?笔者在实践中发现,在RTC驱动中可以很容易实现。在RTC驱动加载的时候,一般都有个probe函数需要先执行,因此在probe函数里下手最直接有效。RTC从1970-01-01开始,那当然很容易把默认值设置到2012-01-01,所需要设置的seconds也就是从1970-01-01所差的秒数,以秒为单位。因此,一旦读出来的RTC值小于我们预想的值比如2012-01-01(1325402913)小,我们就把它设置到这个时间点。

[cpp] view plaincopy

1.  seconds = rtc_read_time();

2.  printk("init PMU/RTC time to  %ld \n", seconds);

3.

4.  if(seconds <= 1325402913) {

5.      seconds = 1325402913;/*2012-01-01*/

6.      ret = rtc_set_time(seconds);

7.      RTC_DBG("Init Set time: %ld, ret =0x%x\n", seconds, ret);

8.  }

笔者通过结果显示,在android平台上是可行的。要设置到哪天几点几分,只要算好具体1970-01-01 00:00差的秒数即可,简单明了。这样客户、用户使用起来更方便一些。

AndroidX86模拟器Genymotion的一些使用和另一款Andy模拟器的更多相关文章

  1. 安卓模拟器genymotion连接eclipse成功但是不显示其中项目

    安卓模拟器困了我两三天了,原装模拟器比较慢,忍受不了,查到安卓模拟器的神器——genymotion 按照网上的步骤一步步都安装完毕,最后打开后发现,genymotion界面里面没有找到新建的工程, 这 ...

  2. (转)最强Android模拟器genymotion的安装与配置

    Android开发人员都知道,原生的模拟器启动比较慢,操作起来也不流畅,还会出现莫名的问题.当然很多人都会选择直接使用android手机来开发,但是有时候需要在投影仪上演示程序的时候手机不太好做到吧. ...

  3. 用android模拟器Genymotion定位元素

    1.下载并安装android模拟器Genymotion 2.拖apk包到模拟器,双击模拟器中的apk软件包,进入应用程序 3.下载并安装android sdk 3.1 点击...\Android\an ...

  4. 最强Android模拟器genymotion的安装与配置

    Android开发人员都知道,原生的模拟器启动比较慢,操作起来也不流畅,还会出现莫名的问题.当然很多人都会选择直接使用android手机来开发,但是有时候需要在投影仪上演示程序的时候手机不太好做到吧. ...

  5. Android模拟器Genymotion安装向导

    Genymotion简述 Genymotion提供Android虚拟环境的工具集.相信很多Android开发者一定受够了速度慢.体验差效率及其地下的官方模拟器了.如果你没有物理机器,又不想忍受官方模拟 ...

  6. Android模拟器genymotion安装与eclipse 插件安装

    推荐一款Android模拟器"Genymotion",有点速度快,占用资源少,可整合eclipse.闲话少谈,看安装步骤. 1.下载地址:https://www.genymotio ...

  7. Eclipse+超快速的模拟器Genymotion开展Android申请书(第一步:安装和配置Genymotion)

    一.安装和配置Genymotion (1)因为Eclipse自带SDK模拟器,慢启动,别说 今天给大家介绍一个更快速的模拟器Genymotion (2)第一次去Genymotion在官方网站上注册一个 ...

  8. Genymotion Android模拟器Genymotion的安装和使用

    Android模拟器Genymotion的安装和使用 by:授客 QQ:1033553122 环境: Win7 Genymotion 2.12.0 下载地址:http://download.canad ...

  9. 【Android Studio安装部署系列】三十二、Android模拟器Genymotion安装使用教程详解

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 一.注册\登录 打开Genymotion官网,https://www.genymotion.com/ ,首先点击右上角的Sign in进行 ...

随机推荐

  1. 【BZOJ1413】取石子游戏(博弈,区间DP)

    题意:在研究过Nim游戏及各种变种之后,Orez又发现了一种全新的取石子游戏,这个游戏是这样的: 有n堆石子,将这n堆石子摆成一排.游戏由两个人进行,两人轮流操作,每次操作者都可以从最左或最右的一堆中 ...

  2. js动态添加select菜单 联动菜单

    原文发布时间为:2009-11-14 -- 来源于本人的百度文章 [由搬家工具导入] <html> <head> <title>http://hi.baidu.co ...

  3. 当文字过长时裁剪(显示省略号或只裁剪 用CSS方法,不用程序)

    原文发布时间为:2009-09-16 -- 来源于本人的百度文章 [由搬家工具导入] CSS中ellipsis()应用【转】 CSS手册中text-overflow属性的定义:   语法: text- ...

  4. [LeetCode] Minimum Depth of Binary Tree 二叉树最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  5. 【jetty】Jetty与Tomcat的区别

    Jetty 的架构从前面的分析可知,它的所有组件都是基于 Handler 来实现,当然它也支持 JMX.但是主要的功能扩展都可以用 Handler 来实现.可以说 Jetty 是面向 Handler ...

  6. poj 2778 DNA Sequence 状态及状态转移 AC自动机 矩阵快速幂

    题目链接 题意 给定\(m\)个字符串,问长度为\(n\)的字符串中有多少个不包含那\(m\)个字符串. (字符集为\(A,T,C,G\),\(m\leq 10\),长度\(\leq 10\),\(n ...

  7. 了解 Oracle Berkeley DB 可以为您的应用程序带来 NoSQL 优势的原因及方式。

    将 Oracle Berkeley DB 用作 NoSQL 数据存储 作者:Shashank Tiwari 2011 年 2 月发布 “NoSQL”是在开发人员.架构师甚至技术经理中新流行的一个词汇. ...

  8. Linux:supervisor命令的使用

    supervisor是Linux下一个便利的启动和监控服务的命令. 举例来说:假如我想同时管理一堆的服务,包括他们的运行和停止.我就可以使用supervisor来管理.   supervisor包括两 ...

  9. FormatDateTime 当前时间减去几小时的做法

    top_start_modified := FormatDateTime('yyyy-mm-dd hh:mm:ss',(Now - ((1/24)*3)));    top_end_modified ...

  10. html5---音频视频基础一

    //html5 音频和视频 :标签 a: audio,video b: source :视频容器 a:容器文件,类似于压缩了一组文件 -音频轨道 -视频轨道 -元数据:封面,标题,字幕等 -格式:.a ...