Android 手机几个有用的命令


几个有用的android 的命令,备查:

input , svc, am, pm, ime, monkey

 input:
 Usage: input [<source>] <command> [<arg>...]

The sources are: 
      keyboard
      mouse
      joystick
      touchnavigation
      touchpad
      trackball
      dpad
      stylus
      gamepad
      touchscreen

The commands and default sources are:
      text <string> (Default: touchscreen)
      keyevent [--longpress] <key code number or name> ... (Default: keyboard)
      tap <x> <y> (Default: touchscreen)
      swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
      press (Default: trackball)
      roll <dx> <dy> (Default: trackball)
 值得关注是cmd: text  和 keyevent

input text www.baidu.com

这个命令可以向手机上输入“www.baidu.com” 这个字串,
如果光标在brower 地址输入栏,这个命令可以通过PC上键盘输入。


input keyevent 26

这是模拟power key 一次输入,如果手机屏幕关闭, 它可以使它亮起来。
反之,使之关闭。
注意,这里power key 的key code是26,而不是116, 应该116是kernel层的,

26是framework层的。

其中value以及对应的key code如下表所列, 如上面命令,可以直接用数据26,也可以用KEYCODE_POWER

KeyEvent Value

KEYCODE

Comment

0

KEYCODE_UNKNOWN

 

1

KEYCODE_MENU

SDK2.1的模拟器中命令失效,sendevent命令可行

2

KEYCODE_SOFT_RIGHT

 

3

KEYCODE_HOME

 

4

KEYCODE_BACK

 

5

KEYCODE_CALL

 

6

KEYCODE_ENDCALL

 

7

KEYCODE_0

 

8

KEYCODE_1

 

9

KEYCODE_2

 

10

KEYCODE_3

 

11

KEYCODE_4

 

12

KEYCODE_5

 

13

KEYCODE_6

 

14

KEYCODE_7

 

15

KEYCODE_8

 

16

KEYCODE_9

 

17

KEYCODE_STAR

 

18

KEYCODE_POUND

 

19

KEYCODE_DPAD_UP

 

20

KEYCODE_DPAD_DOWN

 

21

KEYCODE_DPAD_LEFT

 

22

KEYCODE_DPAD_RIGHT

 

23

KEYCODE_DPAD_CENTER

 

24

KEYCODE_VOLUME_UP

 

25

KEYCODE_VOLUME_DOWN

 

26

KEYCODE_POWER

 

27

KEYCODE_CAMERA

 

28

KEYCODE_CLEAR

 

29

KEYCODE_A

 

30

KEYCODE_B

 

31

KEYCODE_C

 

32

KEYCODE_D

 

33

KEYCODE_E

 

34

KEYCODE_F

 

35

KEYCODE_G

 

36

KEYCODE_H

 

37

KEYCODE_I

 

38

KEYCODE_J

 

39

KEYCODE_K

 

40

KEYCODE_L

 

41

KEYCODE_M

 

42

KEYCODE_N

 

43

KEYCODE_O

 

44

KEYCODE_P

 

45

KEYCODE_Q

 

46

KEYCODE_R

 

47

KEYCODE_S

 

48

KEYCODE_T

 

49

KEYCODE_U

 

50

KEYCODE_V

 

51

KEYCODE_W

 

52

KEYCODE_X

 

53

KEYCODE_Y

 

54

KEYCODE_Z

 

55

KEYCODE_COMMA

 

56

KEYCODE_PERIOD

 

57

KEYCODE_ALT_LEFT

 

58

KEYCODE_ALT_RIGHT

 

59

KEYCODE_SHIFT_LEFT

 

60

KEYCODE_SHIFT_RIGHT

 

61

KEYCODE_TAB

 

62

KEYCODE_SPACE

 

63

KEYCODE_SYM

 

64

KEYCODE_EXPLORER

 

65

KEYCODE_ENVELOPE

 

66

KEYCODE_ENTER

 

67

KEYCODE_DEL

 

68

KEYCODE_GRAVE

 

69

KEYCODE_MINUS

 

70

KEYCODE_EQUALS

 

71

KEYCODE_LEFT_BRACKET

 

72

KEYCODE_RIGHT_BRACKET

 

73

KEYCODE_BACKSLASH

 

74

KEYCODE_SEMICOLON

 

75

KEYCODE_APOSTROPHE

 

76

KEYCODE_SLASH

 

77

KEYCODE_AT

 

78

KEYCODE_NUM

 

79

KEYCODE_HEADSETHOOK

 

80

KEYCODE_FOCUS

 

81

KEYCODE_PLUS

 

82

KEYCODE_MENU

 

83

KEYCODE_NOTIFICATION

 

84

KEYCODE_SEARCH

 

85

TAG_LAST_KEYCODE

 


frameworks/base/core/java/android/view/KeyEvent.java:

    public static final int KEYCODE_VOLUME_UP       = 24;
    /** Key code constant: Volume Down key.
     * Adjusts the speaker volume down. */
    public static final int KEYCODE_VOLUME_DOWN     = 25;
    /** Key code constant: Power key. */
    public static final int KEYCODE_POWER           = 26;

svc: 
shell@Z01B_1:/ $ svc help
Available commands:
    help     Show information about the subcommands
    power    Control the power manager
    data     Control mobile data connectivity
    wifi     Control the Wi-Fi manager
    usb      Control Usb state
    nfc      Control NFC functions
    
shell@Z01B_1:/ $ svc help power 
Control the power manager

usage: svc power stayon [true|false|usb|ac|wireless]
         Set the 'keep awake while plugged in' setting.
       svc power reboot [reason]
         Perform a runtime shutdown and reboot device with specified reason.
       svc power shutdown
         Perform a runtime shutdown and power off the device.

svc power shutdown

可用来关机。

shell@Z01B_1:/ $ svc help usb
Control Usb state

usage: svc usb setFunction [function]
         Set the current usb function.

       svc usb getFunction
          Gets the list of currently enabled functions

shell@Z01B_1:/ $ svc usb getFunction
mtp,adb

svc usb setFunction [function]

可用来设置usb function.

几个命令都可以查看help,monkey 值得一说的是,monkey 可以跑你传给它的脚本,
monkey -f myscript 1

例子:myscript 内容:

================================================================
# This is a sample test script
# Lines starting with '#' are comments
# This part is the "header"
# monkey doesn't actually look for 'type', but does require 'count', 'speed' and
# 'start data >>'
type= custom
count= 100
speed= 1.0
start data >>
# These are the actual instructions to carry out
LaunchActivity(com.android.contacts,com.android.contacts.TwelveKeyDialer)
# Use this instead in 4.2./Jelly Bean (line-wrap is for book, remove to run)
#
LaunchActivity(com.android.contacts,com.android.contacts.activities.Dialtact
#
sActivity)
UserWait(2500)
DispatchPress(KEYCODE_1)
UserWait(200)
DispatchPress(KEYCODE_8)
UserWait(200)
DispatchPress(KEYCODE_0)
UserWait(200)
DispatchPress(KEYCODE_0)
UserWait(200)
DispatchPress(KEYCODE_8)
UserWait(200)
DispatchPress(KEYCODE_8)
UserWait(200)
DispatchPress(KEYCODE_9)
UserWait(200)
DispatchPress(KEYCODE_8)
UserWait(200)
DispatchPress(KEYCODE_9)
UserWait(200)
DispatchPress(KEYCODE_6)
UserWait(200)
DispatchPress(KEYCODE_9)
UserWait(200)
DispatchPress(KEYCODE_ENTER)
UserWait(10000)
DispatchPress(KEYCODE_ENDCALL)
UserWait(200)
RunCmd(input keyevent 3)
UserWait(1000)
RunCmd(service call statusbar 1)
UserWait(2000)
RunCmd(service call statusbar 2)
================================================================

如果要查看脚本中可以用哪些函数,可以查看development/cmds/monkey/src/com/android/commands/
monkey/MonkeySourceScript.java



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值