赞
踩
为了自动测试拨打电话功能,自动化脚本需要使用相关的接口。
方法之一:AT command
1) adb shell
2) enter AT command mode ( platform specific )
3) atd112; // 拨打112
4) ath // 断开MO call
方法之二:Android am command
1)adb shell
2) am start -a android.intent.action.CALL -d tel:112 // 输入112号码
3)input keyevent 66 // 开始拨号
4) input keyevent 6 // 断开
综合考虑,如果需要针对modem方面的操作, AT 命令比较方便。
如果需要对application processor方面的应用进行操作, android am 命令比较合适。
===================================================================
am 命令
- usage: am [subcommand] [options]
- usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]
- [--R COUNT] [-S] [--opengl-trace]
- [--user <USER_ID> | current] <INTENT>
- am startservice [--user <USER_ID> | current] <INTENT>
- am force-stop [--user <USER_ID> | all | current] <PACKAGE>
- am kill [--user <USER_ID> | all | current] <PACKAGE>
- am kill-all
- am broadcast [--user <USER_ID> | all | current] <INTENT>
- am instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w]
- [--user <USER_ID> | current]
- [--no-window-animation] <COMPONENT>
- am profile start [--user <USER_ID> current] <PROCESS> <FILE>
- am profile stop [--user <USER_ID> current] [<PROCESS>]
- am dumpheap [--user <USER_ID> current] [-n] <PROCESS> <FILE>
- am set-debug-app [-w] [--persistent] <PACKAGE>
- am clear-debug-app
- am monitor [--gdb <port>]
- am screen-compat [on|off] <PACKAGE>
- am display-size [reset|WxH]
- am display-density [reset|DENSITY]
- am to-uri [INTENT]
- am to-intent-uri [INTENT]
- am switch-user <USER_ID>
- am stop-user <USER_ID>

am 参数说明
- am start: start an Activity. Options are:
- -D: enable debugging
- -W: wait for launch to complete
- --start-profiler <FILE>: start profiler and send results to <FILE>
- -P <FILE>: like above, but profiling stops when app goes idle
- -R: repeat the activity launch <COUNT> times. Prior to each repeat,
- the top activity will be finished.
- -S: force stop the target app before starting the activity
- --opengl-trace: enable tracing of OpenGL functions
- --user <USER_ID> | current: Specify which user to run as; if not
- specified then run as the current user.
-
- am startservice: start a Service. Options are:
- --user <USER_ID> | current: Specify which user to run as; if not
- specified then run as the current user.
-
- am force-stop: force stop everything associated with <PACKAGE>.
- --user <USER_ID> | all | current: Specify user to force stop;
- all users if not specified.
-
- am kill: Kill all processes associated with <PACKAGE>. Only kills.
- processes that are safe to kill -- that is, will not impact the user
- experience.
- --user <USER_ID> | all | current: Specify user whose processes to kill;
- all users if not specified.
-
- am kill-all: Kill all background processes.
-
- am broadcast: send a broadcast Intent. Options are:
- --user <USER_ID> | all | current: Specify which user to send to; if not
- specified then send to all users.
-
- am instrument: start an Instrumentation. Typically this target <COMPONENT>
- is the form <TEST_PACKAGE>/<RUNNER_CLASS>. Options are:
- -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with
- [-e perf true] to generate raw output for performance measurements.
- -e <NAME> <VALUE>: set argument <NAME> to <VALUE>. For test runners a
- common form is [-e <testrunner_flag> <value>[,<value>...]].
- -p <FILE>: write profiling data to <FILE>
- -w: wait for instrumentation to finish before returning. Required for
- test runners.
- --user <USER_ID> | current: Specify user instrumentation runs in;
- current user if not specified.
- --no-window-animation: turn off window animations will running.
-
- am profile: start and stop profiler on a process. The given <PROCESS> argument
- may be either a process name or pid. Options are:
- --user <USER_ID> | current: When supplying a process name,
- specify user of process to profile; uses current user if not specified.
-
- am dumpheap: dump the heap of a process. The given <PROCESS> argument may
- be either a process name or pid. Options are:
- -n: dump native heap instead of managed heap
- --user <USER_ID> | current: When supplying a process name,
- specify user of process to dump; uses current user if not specified.
-
- am set-debug-app: set application <PACKAGE> to debug. Options are:
- -w: wait for debugger when application starts
- --persistent: retain this value
-
- am clear-debug-app: clear the previously set-debug-app.
-
- am bug-report: request bug report generation; will launch UI
- when done to select where it should be delivered.
- am monitor: start monitoring for crashes or ANRs.
- --gdb: start gdbserv on the given port at crash/ANR
-
- am screen-compat: control screen compatibility mode of <PACKAGE>.
-
- am display-size: override display size.
-
- am display-density: override display density.
-
- am to-uri: print the given Intent specification as a URI.
-
- am to-intent-uri: print the given Intent specification as an intent: URI.
-
- am switch-user: switch to put USER_ID in the foreground, starting
- execution of that user if it is currently stopped.
-
- am stop-user: stop execution of USER_ID, not allowing it to run any
- code until a later explicit switch to it.

input 命令
- usage: input ...
- input text <string>
- input keyevent <key code number or name>
- input [touchscreen|touchpad] tap <x> <y>
- input [touchscreen|touchpad] swipe <x1> <y1> <x2> <y2>
- input trackball press
- input trackball roll <dx> <dy>
Android KeyEvent 输入Android keyevent 输入
- case 0x0a: case 0x8a: system("input keyevent 3");break;//Home
- case 0x0b: case 0x8b: system("input keyevent 82");break;//menu
- case 0x1c: case 0x9c: system("input keyevent 19");break;//up
- case 0x1d: case 0x9d: system("input keyevent 20");break;//down
- case 0x1e: case 0x9e: system("input keyevent 23");break;//OK
- case 0x1f: case 0x9f: system("input keyevent 21");break;//left
- case 0x20: case 0xa0: system("input keyevent 22");break;//right
- case 0x21: case 0xa1: system("input keyevent 67");break;//Back
- case 0x22: case 0xa2: system("input keyevent 4");break;//Exit
- case 0x23: case 0xa3: /*system("input keyevent 6");*/break;//i
- case 0x28: case 0xa8: /*system("input keyevent 28");*/break;//A-select
- case 0x29: case 0xa9: /*system("input keyevent 66");*/break;//B - Enter
- case 0x2a: case 0xaa: /*system("input keyevent ");*/break;//white
- case 0x2b: case 0xab: /*system("input keyevent 26");*/break;//green - Power
- case 0x2c: case 0xac: /*system("input keyevent ");*/break;//yellow
- case 0x2d: case 0xad: /*system("input keyevent 1");*/break;//red
- case 0x2e: case 0xae: system("input keyevent 24");break;//volume up
- case 0x2f: case 0xaf: system("input keyevent 25");break;//volume down
- case 0x00: case 0x80: system("input keyevent 7");break;//0
- case 0x01: case 0x81: system("am start -n com.cooliris.media/.Gallery");break;//1
- case 0x02: case 0x82: system("am start -n com.android.browser/.BrowserActivity");break;//2
- case 0x03: case 0x83: system("am start -n com.android.settings/.WirelessSettings");break;//3
- case 0x04: case 0x84: /*system("input keyevent 11");*/break;//4
- case 0x05: case 0x85: /*system("input keyevent 12");*/break;//5
- case 0x06: case 0x86: /*system("input keyevent 13");*/break;//6
- case 0x07: case 0x87: /*system("input keyevent 14");*/break;//7
- case 0x08: case 0x88: /*system("input keyevent 15");*/break;//8
- case 0x09: case 0x89: /*system("input keyevent 16");*/break;//9

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。