码迷,mamicode.com
首页 > 移动开发 > 详细

Android 通过adb shell am broadcast发送广播

时间:2016-09-20 11:46:31      阅读:5777      评论:0      收藏:0      [点我收藏+]

标签:

Android 通过adb shell am broadcast发送广播

adb shell am broadcast 后面的参数有:


[-a <ACTION>]
[-d <DATA_URI>]
[-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[-n <COMPONENT>]
[-f <FLAGS>] [<URI>]

 

例如:

adb shell am broadcast -a com.android.test --es test_string "this is test string" --ei test_int 100 --ez test_boolean true

 

说明:蓝色为key,红色为alue,分别为String类型,int类型,boolean类型

 

db shell am instrument [options] <COMPONENT>

作用:启动对instrument实例的监视。

参数[options]:

-e <key> <value> // -e选项需要放在-w选项之前

作用:提供了以键值对形式存在的测试选项。Android中提供了多种键值对,具体参见下表。
举例:-e class com.android.phone.FIncomingCallTests#testRejectCall

-r

作用:以原始形式输出测试结果。该选项通常是在性能测试时与-e perf true一起使用。

参数 <COMPONENT>:

-w <test_package_name>/<runner_class> //<test_package_name>和<runner_class>在测试工程的AndroidManifest.xml中查找

作用:保持adb shell打开直至测试完成
举例:-w com.android.phone.tests/com.android.phone.runners.FunctionalTestRunner

<key> <value>参考表

Key Value Description
package <Java_package_name> The fully-qualified Java package name for one of the packages in the test application. Any test case class that uses this package name is executed. Notice that this is not an Android package name; a test package has a single Android package name but may have several Java packages within it.
class <class_name> The fully-qualified Java class name for one of the test case classes. Only this test case class is executed.
<class_name>#method name A fully-qualified test case class name, and one of its methods. Only this method is executed. Note the hash mark (#) between the class name and the method name.
func true Runs all test classes that extend InstrumentationTestCase.
unit true Runs all test classes that do not extend either InstrumentationTestCase orPerformanceTestCase.
size [small | medium | large] Runs a test method annotated by size. The annotations are @SmallTest,@MediumTest, and @LargeTest.
perf true Runs all test classes that implement PerformanceTestCase. When you use this option, also specify the -r flag for am instrument, so that the output is kept in raw format and not re-formatted as test results.
debug true Runs tests in debug mode.
log true Loads and logs all specified tests, but does not run them. The test information appears in STDOUT. Use this to verify combinations of other filters and test specifications.
emma true Runs an EMMA code coverage analysis and writes the output to/data//coverage.ec on the device. To override the file location, use thecoverageFile key that is described in the following entry.
Note: This option requires an EMMA-instrumented build of the test application, which you can generate with the coverage target.

coverageFile <filename>
Overrides the default location of the EMMA coverage file on the device. Specify this value as a path and filename in UNIX format. The default filename is described in the entry for the emma key

 

adb shell am start [options] <INTENT>

作用:启动一个activity

举例:adb shell am start -a com.lt.test.action.SECOND

举例:adb shell am start -n com.lt.test/.MyActivity

说明:[options]与<INTENT>参见 http://developer.android.com/tools/help/adb.html#am

adb shell am startservice [options] <INTENT>

作用:启动一个service

举例:adb shell am startservice -a com.lt.test.action.ONESERVICE
举例:adb shell am startservice -n com.lt.test/.MyService

 

adb shell am force-stop <PACKAGE>
作用:强制关闭一个应用程序

举例:adb shell am force-stop com.lt.test

 

adb shell am broadcast [options] <INTENT>

作用:发送一个广播
举例:adb shell am broadcast -a "action_finish" (发送一个广播去关闭一个activity)
举例:adb shell am broadcast -a android.intent.action.MASTER_CLEAR(恢复出厂设置的方法,会清除内存所有内容)

举例:adb shell am broadcast -n com.lt.test/.MyBroadcast

 

adb shell pm list packages [options] <INTENT>

作用:列举出所有包含<INTENT>的package

举例:adb shell pm list packages com.lt

说明:[options]与<INTENT>参见 http://developer.android.com/tools/help/adb.html#pm

 

参考链接:

http://developer.android.com/tools/help/adb.html

 

==========================================================================================

扩展阅读:

 

第一部分:

1. ubuntu下配置环境anroid变量:

在终端执行 sudo gedit /etc/profile 打开文本编辑器,在最后追加#set android environment

2. 运行Eclipse,还需要配置JAVA环境变量

#set java environment

JAVA_HOME=/home/loginname/jdk目录名

JRE_HOME=/home/loginname/jdk目录名/jre

export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

export PATH=/home/loginname/android-sdk-linux_86/tools:$PATH

保存后,重启

3. 加入设备ID标识到当前的android调试环境

在/home/loginname/.android文件中添加,android终端的设备标识ID

4. 更新sdk

【android update sdk】更新sdk

5. 常用命令:

【adb help】获取帮助

【adb get-serialno】获取设备串号

【adb root】获取root权限,对部分手机有用,大部分上市手机已经把这个功能给关闭了。获取root权限还可以通过豌豆夹等第三方工具。

【adb kill-server】杀死adb的server进程。

【adb start-server】启动adb的server进程。

【adb devices】查看建立连接的android终端。

【android list】显示所有android终端

【ddms】启动ddms

【adb remount】重新加载硬盘。

【adb reboot】重新启动终端。

【adb install /path/appname】安装应用程序

【adb uninstall com.android.helloworld】卸载helloworld,系统带的应用不可卸载。

【adb push /sourcepath/filename /destinationpath/filename】从pc端拷贝一个文件到终端

【adb pull /sourcepath/filename /destinationpath/filename】从终端拷贝一个文件到pc端

【adb logcat -v time -s TAGNAME】显示自定义的TAGNAME并显示时间

【adb ppp】通过usb启动ppp

【adb monkey -p /path/appname -v 100】对程序进行强制测试100次

【adb shell】在pc端启动shell命令终端。

以上命令需要pc端的root权限(腾云科技ty300.com),命令失效时,可以尝试切换工作目录到sdk的tools下,例如:sudo ./adb kill-server,sudo ./adb start-server。

6. shell下命令,可以使用BusyBox工具集:

【am start -n {包名(package)}/{包名}.{活动activity名称}】启动某一个app的activity,配置参考AndroidManifest.xml,例如闹钟:
# am start -n com.android.alarmclock/com.android.alarmclock.AlarmClock

【am broadcast -a android.intent.action.ActionName】发送广播消息

【setprop KEY VALUE】设置key的property值位value

【getprop KEY】获取该key的property值

【getevent】获取所有事件

【watchprops】监听property值的变化

【stop SERVER】强行停止某一个服务

【start SERVER】启动某一个服务

【ioctl】控制设备

【dumpsys activity】显示活动栈信息

【top】显示瞬间的进程的资源占用等信息

【free】显示当前进程内存使用情况

【ps】显示进程的自身标识信息

【rm /path/filename】从终端删除一个文件

【mkdir】新建一个目录或者文件

【grep】查找特定内容

【ls】显示当前目录下的文件

【cd】切换当前目录

【chmod】更改文件属性

【cp】拷贝文件

【dd】复制文件

【mv】移动目录文件,或者改名

【cat】查看文件内容

【kill】杀死进程

【ipconfig】查看更改网络接口地址和参数

【ping】检测网络状态

【netstat】查看网络状态

【telnet】登录远程主机

【sqlite3 /path/DATABASENAME.db】打开某一个数据库。之后即可使用select,insert,delete等数据库操作命令

【tcpdump -p -nnn -vvv -s 0 -w /PATH/NAME.pcap port 80 and tcp】网络调试抓包

【gst-launch playbin uri=file:///system/media/audio/bootaudio.mp3】gst多媒体框架,播放音频文件

【alsa_amixer】音频调试命令,可以切换声道,调节音量,切换设备。不同的芯片厂家的参数设置有所不同。

【alsa_aplay -D AndroidPlayback_Speaker_normal /cache/music/dial/0.wav】通过alsa播放pcm码流。

【alsa_arecord】通过alsa实现录音

【am start -n com.android.music/com.android.music.MediaPlaybackActivity -d /sdcard/bootaudio.mp3】启动android进程播放mp3

【stack --symbols-dir=./out/target/product/NAME/symbols ramdump】查看调用堆栈

【exit】退出shell

通过 adb shell, cd /system/bin,ls可以列表出大部分可用的命令。

稿源:勤快学QKXue.NET

扩展阅读:

http://qkxue.net/info/24437/Android-adb-shell-broadcast

Android 通过adb shell am broadcast发送广播

标签:

原文地址:http://www.cnblogs.com/qkxue/p/5887978.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!