Android Console Commands 指令

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

adb shell 指令有很多,可參考官網的說明。底下列出筆者常用的指令。

=======================================================================
底下指令可查到 Android的軟體版本
cat /system/build.prop | busybox grep "ro.build.description"

=======================================================================
開啟網頁瀏覽器
./adb shell am start -a android.intent.action.VIEW -d http://tw.yahoo.com/
./adb shell am start -n com.android.chrome/com.google.android.apps.chrome.Main

=======================================================================
無線網路相關指令
// Scan Wireless AP
iwlist wlan0 scan

// 連線至指定名稱(essid)的AP
iwconfig wlan0 essid "指定名稱"
例如:
iwconfig wlan0 essid "holan"
會連線到 ssid 為 holan 的AP。

// 查詢 wifi 設定
iwconfig wlan0

// 設定固定IP
busybox ifconfig wlan0 192.168.1.123 netmask 255.255.255.0

// 設定動態IP(dhcp)
netcfg wlan0 dhcp

// 關閉 Wifi
busybox ifconfig wlan0 down

// 開啟 Wifi
busybox ifconfig wlan0 up

// 關閉 Ethernet
busybox ifconfig eth0 down

// 設定 WEP 的 key (ex. 12345678901234567890123456
// (128 bits),一共有 26 個數字)。
sudo iwconfig wlan0 key 12345678901234567890123456

open wireless ap

svc wifi enable
svc wifi disable

=======================================================================
開啟錄影機程式
adb shell am start -n com.android.camera/.Camera
adb shell am start -n com.android.camera/.VideoCamera
adb shell am start -n android.provider.MediaStore -

=======================================================================
利用 adb 輸入 keyevent
adb shell input keyevent 7    # for key '0'
adb shell input keyevent 8    # for key '1'
adb shell input keyevent 29    # for key 'A'
adb shell input keyevent 54    # for key 'B'

輸入字串
adb shell input text "ANDROID"

Keycode 列表
00 ->  "KEYCODE_UNKNOWN"
01 ->  "KEYCODE_MENU"
02 ->  "KEYCODE_SOFT_RIGHT"
03 ->  "KEYCODE_HOME"
04 ->  "KEYCODE_BACK"
05 ->  "KEYCODE_CALL"
06 ->  "KEYCODE_ENDCALL"
07 ->  "KEYCODE_0"
08 ->  "KEYCODE_1"
09 ->  "KEYCODE_2"
10 ->  "KEYCODE_3"
11 ->  "KEYCODE_4"
12 -?  "KEYCODE_5"
13 ->  "KEYCODE_6"
14 ->  "KEYCODE_7"
15 ->  "KEYCODE_8"
16 ->  "KEYCODE_9"
17 ->  "KEYCODE_STAR"
18 ->  "KEYCODE_POUND"
19 ->  "KEYCODE_DPAD_UP"
20 ->  "KEYCODE_DPAD_DOWN"
21 ->  "KEYCODE_DPAD_LEFT"
22 ->  "KEYCODE_DPAD_RIGHT"
23 ->  "KEYCODE_DPAD_CENTER"
24 ->  "KEYCODE_VOLUME_UP"
25 ->  "KEYCODE_VOLUME_DOWN"
26 ->  "KEYCODE_POWER"
27 ->  "KEYCODE_CAMERA"
28 ->  "KEYCODE_CLEAR"
29 ->  "KEYCODE_A"
30 ->  "KEYCODE_B"
31 ->  "KEYCODE_C"
32 ->  "KEYCODE_D"
33 ->  "KEYCODE_E"
34 ->  "KEYCODE_F"
35 ->  "KEYCODE_G"
36 ->  "KEYCODE_H"
37 ->  "KEYCODE_I"
38 ->  "KEYCODE_J"
39 ->  "KEYCODE_K"
40 ->  "KEYCODE_L"
41 ->  "KEYCODE_M"
42 ->  "KEYCODE_N"
43 ->  "KEYCODE_O"
44 ->  "KEYCODE_P"
45 ->  "KEYCODE_Q"
46 ->  "KEYCODE_R"
47 ->  "KEYCODE_S"
48 ->  "KEYCODE_T"
49 ->  "KEYCODE_U"
50 ->  "KEYCODE_V"
51 ->  "KEYCODE_W"
52 ->  "KEYCODE_X"
53 ->  "KEYCODE_Y"
54 ->  "KEYCODE_Z"
55 ->  "KEYCODE_COMMA"
56 ->  "KEYCODE_PERIOD"
57 ->  "KEYCODE_ALT_LEFT"
58 ->  "KEYCODE_ALT_RIGHT"
59 ->  "KEYCODE_SHIFT_LEFT"
60 ->  "KEYCODE_SHIFT_RIGHT"
61 ->  "KEYCODE_TAB"
62 ->  "KEYCODE_SPACE"
63 ->  "KEYCODE_SYM"
64 ->  "KEYCODE_EXPLORER"
65 ->  "KEYCODE_ENVELOPE"
66 ->  "KEYCODE_ENTER"
67 ->  "KEYCODE_DEL"
68 ->  "KEYCODE_GRAVE"
69 ->  "KEYCODE_MINUS"
70 ->  "KEYCODE_EQUALS"
71 ->  "KEYCODE_LEFT_BRACKET"
72 ->  "KEYCODE_RIGHT_BRACKET"
73 ->  "KEYCODE_BACKSLASH"
74 ->  "KEYCODE_SEMICOLON"
75 ->  "KEYCODE_APOSTROPHE"
76 ->  "KEYCODE_SLASH"
77 ->  "KEYCODE_AT"
78 ->  "KEYCODE_NUM"
79 ->  "KEYCODE_HEADSETHOOK"
80 ->  "KEYCODE_FOCUS"
81 ->  "KEYCODE_PLUS"
82 ->  "KEYCODE_MENU"
83 ->  "KEYCODE_NOTIFICATION"
84 ->  "KEYCODE_SEARCH"
85 ->  "TAG_LAST_KEYCODE"

1. "stop media" 將 android 對 audio 的控制釋放。
2. "stop" 將 android 停止。

=======================================================================
動態 IP 指令
getprop net.eth0
getprop net.eth0.dns1
netcfg eth0 up
netcfg eth0 dhcp

/system/bin/netcfg eth0 dhcp
/system/bin/netcfg eth0 down

setprop net.gprs.http-proxy http://10.0.0.25:3128
setprop net.dns1 [IP address of your DNS server]
setprop net.dns2 [IP address of your DNS server]

=======================================================================
靜態 IP 指令
busybox ip addr flush eth0

// MAC
busybox ifconfig eth0 hw ether 12:34:56:78:90:12
busybox ifconfig eth0 hw ether E0:CB:4E:C2:BA:F6
busybox ifconfig eth0 hw ether 10:20:30:40:50:60

busybox ifconfig eth0 172.18.13.103 netmask 255.255.255.0
busybox ifconfig eth0 192.168.1.23 netmask 255.255.255.0

busybox ifconfig eth0 172.18.13.10 netmask 255.255.255.0
busybox route add default gw 172.18.13.254 eth0

setprop net.dns1 [IP address of your DNS server]
setprop net.dns2 [IP address of your DNS server]
setprop net.gprs.http-proxy http://10.0.0.25:3128

setprop net.dns1 10.0.5.11
setprop net.dns2 10.0.5.35
setprop net.gprs.http-proxy http://10.0.0.25:3128


=======================================================================
設定 HTTP-Proxy 指令
getprop net.gprs.http-proxy
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure VALUES(100,'http_proxy','http://10.0.0.25:3128');"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "select * from secure;"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "update secure set value='10.0.0.25:3128' where name='http_proxy'"

=======================================================================
使用模擬器測試 ACTION_BOOT_COMPLETED

adb shell am activity/service/broadcast -a ACTION -c CATEGORY -n NAME

example:
adb shell am broadcast
  -a android.intent.action.BOOT_COMPLETED
  -c android.intent.category.HOME
  -n your_package_name/.StartupReceiver

android/com.android.internal.app.ResolverActivity

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

沒有留言: