Android:adb 启动activity、service,发送broadcast

一、adb启动activity:

$ adb shell

$ am start -n {包(package)名}/{包名}.{活动(activity)名称}

如:启动浏览器

# am start -n com.android.browser/com.android.browser.BrowserActivity

二、adb启动service:

$ adb shell

$ am startservice -n

{包(package)名}/{包名}.{服务(service)名称}

如:启动自己应用中一个service

# am startservice -n com.android.traffic/com.android.traffic.maniservice

三、adb发送broadcast:

$ adb shell

$ am broadcast -a

如:发送一个网络变化的广播

# am broadcast -a android.net.conn.CONNECTIVITY_CHANGE

通过命令行执行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 --estest_string"this is test string"--ei test_int100--ez test_booleantrue

results matching ""

    No results matching ""