網頁

2015年3月21日 星期六

如何在電腦上使用 ADB指令操作Android手機(How to use adb to manipulate android mobile phone )

( 2018/12/16 最新修改版)
如何安裝 adb(Android Debug Bridge)

1.下載 Android SDK Tools
點選下面「RELEASE NOTES」。
2.點選左邊的 SDK platfrom tools」。
3.點選右邊的「SDK Platform-Tools for Windows」。
4. 勾選「I have read and agree with the above terms and conditions」,按「DOWNLOAD SDK Platform-Tools for Windows」此按鈕 。
5.選已下載的「platform-tools_r28.0.1-windows.zip 」,按右鍵,解壓縮出來。
6.在 「platform-tools」此資料夾內,全選所有的檔案和子資料夾(Ctrl+A),複製(Ctrl+C)到另一個資料夾(例如 e:\adb )(Ctrl+V)。這樣在命令提示字元裏面,使用adb指令比較方便。
(一般祇要有adb.exeAdbWinApi.dllAdbWinUsbApi.dllfastboot.exe4個檔案即可)

如何執行adb

電腦端要安裝手機的驅動程式,HTC手機請安裝「HTC Sync」,MOTO手機請安裝「Motorola USB drivers」,Samsung手機請安裝「Kies」,LG請安裝「LG Support Tool 」。

1.打開 手機
「設定」 -> 「開發人員選項」 -> 勾選「USB 偵錯」
(如果沒有開發人員選項,
系統設定/標準/關於手機/軟體資訊/版本號碼 上按8下,會出現開發人員的提示,再點兩下點左下實體鍵返回,點 開發者選項,USB偵錯 打勾)

2.將手機用 USB 連接線連到 電腦
在螢幕左下方視窗圖示按右鍵,選「執行」。
輸入「cmd 」,叫出命令提示字元視窗。
或者叫出檔案總管,shift鍵按住不放,選 e:\adb此資料夾,按右鍵,選「在此處開啟命令視窗」(Windows 10,沒有此用法)

切換到 e:\adb
 cd e:\adb

常用 adb 指令大全

 adb devices (顯示目前有多少個模擬器正在執行)
adb devices -l  (顯示目前有多少個模擬器正在執行, 更詳細的資料)
E:\adb>adb devices
List of devices attached
470f02f1 device


E:\adb>adb devices -l
List of devices attached
470f02f1 device product:geefhd_open_tw model:LG_E988
 

adb push  <local> <remote>          - 複製電腦端檔案/資料夾到 SD 卡
adb push J:\software\software\android\download\apk\line.apk  /storage/external_SD/apk

adb push i:\software\software\android\download\apk\gps_map\naviking\NaviKingMap201505\NaviKingMap  /storage/external_SD/Android/data/com.kingwaytek/files/NaviKingMap

adb pull  <remote> [<local>]        - 從SD 卡複製檔案/資料夾到 電腦端
adb pull /sdcard/cwm_6.0.4.7.recovery.img  .\cwm_6.0.4.7.recovery.img

adb reboot (手機重新開機)
adb reboot recovery (手機重新開機,進入recovery 模式)
adb reboot fastboot   (手機重新開機,進入fastboot 模式)


adb shell (進入 Android 系統指令列模式)

常用的shell 指令(跟 linux相同)

dmesg  - 查看 Android Linux Kernel 運作訊息
 ls - 顯示檔案目錄
 cd - 進入目錄
rm - 刪除檔案
 mv - 移動檔案
mkdir - 產生目錄
 rmdir - 刪除目錄
su - 使用 root權限
pwd - 顯示目前路徑名稱
dd - 複製與轉換檔案  copy and convert a file
        if : input file  (輸入檔案)    of :  output file (輸出檔案)
dd if=/sdcard/cwm6.0.4.7.recovery.img of=/dev/block/platform/msm_sdcc.1/by-name/recovery


E:\adb>adb shell 
shell@geefhd:/ $ su
root@geefhd:/ # pwd
root@geefhd:/ # cd data 
root@geefhd:/data #