Android 通過adb shell am broadcast發送廣播

來源:互聯網
上載者:User

標籤:

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>參考表

KeyValueDescription
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 nameA 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.
functrueRuns all test classes that extend InstrumentationTestCase.
unittrueRuns 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.
perftrueRuns 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.
debugtrueRuns tests in debug mode.
logtrueLoads 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.
emmatrueRuns 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發送廣播

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.