Android開發工具–adb的使用

來源:互聯網
上載者:User

adb(Android Debug Bridge)是Android提供的一個通用的調試工具,藉助這個工具,我們可以管理裝置或手機模擬器的狀態。還可以進行以下的操作:

1、快速更新裝置或手機模擬器中的代碼,如應用或Android系統升級;

2、在裝置上運行shell命令;

3、管理裝置或手機模擬器上的預定連接埠;

4、在裝置或手機模擬器上複製或粘貼檔案;

 

以下為一些常用的操作:

1、安裝應用到模擬器:

adb install <path_to_apk></path_to_apk>

比較鬱悶的是,Android並沒有提供一個卸載應用的命令,只能自己手動刪除:

adb shell

cd /data/app

rm app.apk

(聽說可以這樣)

1. 1 卸載軟體[code]
adb uninstall <軟體名>
adb uninstall -k <軟體名>
[/code]如果加 -k 參數,為卸載軟體但是保留配置和快取檔案.

2、進入裝置或模擬器的shell:

adb shell

通過上面的命令,就可以進入裝置或模擬器的shell環境中,在這個Linux Shell中,你可以執行各種Linux的命令,另外如果只想執行一條shell命令,可以採用以下的方式:

adb shell [command]

如:adb shell dmesg會列印出核心的調試資訊。

3、發布連接埠:

你可以設定任意的連接埠號碼,做為主機向模擬器或裝置的請求連接埠。如:

adb forward tcp:5555 tcp:8000

4、複製檔案:

你可向一個裝置或從一個裝置中複製檔案,

複製一個檔案或目錄到裝置或模擬器上:

adb push <source> <destination></destination></source>

如:adb push test.txt /tmp/test.txt

從裝置或模擬器上複製一個檔案或目錄:

adb pull <source> <destination></destination></source>

如:adb pull /addroid/lib/libwebcore.so .

5、搜尋模擬器/裝置的執行個體:

取得當前啟動並執行模擬器/裝置的執行個體的列表及每個執行個體的狀態:

adb devices

6、查看bug報告:

adb bugreport

7、記錄無線通訊日誌:

一般來說,無線通訊的日誌非常多,在運行時沒必要去記錄,但我們還是可以通過命令,設定記錄:

adb shell

logcat -b radio

8、擷取裝置的ID和序號:

adb get-product

adb get-serialno

9、訪問資料庫SQLite3

adb shell

sqlite3

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

鍵入“cmd”,cd到tools的目錄下,再鍵入“adb shell”,出現了個“#”號,這樣就可以使用命令來控制Android了
運行“am -help”,可以查看“am”命令的協助資訊,試試運行“am start -n com.google.android.browser/com.google.android.browser.BrowserActivity”看看?呵呵,在模擬器裡面可以看到運行了瀏覽器,哈哈,就是這麼簡單(簡單個P,為了找這個東西花了我好久的時間)。
還有:
//運行瀏覽器,開啟中華網
# am start -a android.intent.action.VIEW -d http://www.china.com
am start -a android.intent.action.VIEW -d http://www.china.com
Starting: Intent { action=android.intent.action.VIEW data=http://www.china.com }

//撥打到電話,號碼是123456789
# am start -a android.intent.action.CALL -d tel:123456789
am start -a android.intent.action.CALL -d tel:123456789
Starting: Intent { action=android.intent.action.CALL data=tel:123456789 }

# am start -a android.intent.action.ALL_APPS
am start -a android.intent.action.ALL_APPS
Starting: Intent { action=android.intent.action.ALL_APPS }

//google地圖,到shanghai這個點包(註:點包為方言,就是地方的意思)
# am start -a android.intent.action.VIEW geo:0,0?q=shanghai
am start -a android.intent.action.VIEW geo:0,0?q=shanghai
Starting: Intent { action=android.intent.action.VIEW data=geo:0,0?q=shanghai }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.