android常用命令

來源:互聯網
上載者:User
 1. Android支援的linux command不多,在/system/bin下面可以找到,其中大部分都是Android的工具,只有一小部分是linux原有的命令

2. 一些常用的Android命令(這裡只總結Android中特有的,其他的linux命令資料就很多了)

a)getprop/watchprops

getprop列出系統的屬性,前面十名字,後面是值
# getprop
getprop
[ro.secure]: [0]
[ro.allow.mock.location]: [1]
[ro.debuggable]: [1]
[persist.service.adb.enable]: [1]
[ro.kernel.qemu]: [1]
[ro.kernel.console]: [ttyS0]
[ro.kernel.android.checkjni]: [1]
[ro.kernel.android.qemud]: [ttyS1]
[ro.kernel.android.ndns]: [1]
[ro.factorytest]: [0]
[ro.serialno]: []

watchprosp動態監視這些屬性的變化,比如我修改系統的語言為中文,就會列印出:
# watchprops
watchprops
1269420653 persist.sys.language = 'zh'
1269420653 persist.sys.language = 'CN'

b) wipe <system|data|all>
wipe表示清除模擬器或者真機上的資料,比如你的模擬器用了很久,裝了很多軟體就可以用這個來清除
system表示清除 /system下的資料
data表述清除 /data 下的資料

c) am
usage: am [subcommand] [options]

  start an Activity: am start [-D] <INTENT>
  -D: enable debugging

  send a broadcast Intent: am broadcast <INTENT>

  start an Instrumentation: am instrument [flags] <COMPONENT>
  -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
  -e <NAME> <VALUE>: set argument <NAME> to <VALUE>
  -p <FILE>: write profiling data to <FILE>
  -w: wait for instrumentation to finish before returning

  start profiling: am profile <PROCESS> start <FILE>
  stop profiling: am profile <PROCESS> stop

  <INTENT> specifications include these flags:
  [-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>]

am是管理activity的工具,主要有4種用法
am start/stop <INTENT> 表示啟動或者停止一個activity,INTENT的參數可以在AndroidManifest.xml中的intent-filter中找到
比如我要開啟發送郵件的activity就可以這樣寫
# am start -a android.intent.action.SEND_MULTIPLE
am start和StartActivity方法是一個作用

am也可以發送一個broadcast,後面的INTENT和上面同
除此之外還可以 start profiling和Instrumentation,這兩個還不知怎麼用,歡迎大家補充

d)pm
pm就是package manager,可以帶下面的參數,因為協助都說的很清楚了,我就不作解釋了
usage: pm [list|path|install|uninstall]
  pm list packages [-f]
  pm list permission-groups
  pm list permissions [-g] [-f] [-d] [-u] [GROUP]
  pm list instrumentation [-f] [TARGET-PACKAGE]
  pm list features
  pm path PACKAGE
  pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] PATH
  pm uninstall [-k] PACKAGE
  pm enable PACKAGE_OR_COMPONENT
  pm disable PACKAGE_OR_COMPONENT

The list packages command prints all packages. Options:
  -f: see their associated file.

The list permission-groups command prints all known
permission groups.

The list permissions command prints all known
permissions, optionally only those in GROUP. Options:
  -g: organize by group.
  -f: print all information.
  -s: short summary.
  -d: only list dangerous permissions.
  -u: list only the permissions users will see.

The list instrumentation command prints all instrumentations,
or only those that target a specified package. Options:
  -f: see their associated file.

The list features command prints all features of the system.

The path command prints the path to the .apk of a package.

The install command installs a package to the system. Options:
  -l: install the package with FORWARD_LOCK.
  -r: reinstall an exisiting app, keeping its data.
  -t: allow test .apks to be installed.
  -i: specify the installer package name.

The uninstall command removes a package from the system. Options:
  -k: keep the data and cache directories around.
after the package removal.

The enable and disable commands change the enabled state of
a given package or component (written as "package/class").

e)svc
svc可硬用來管理wifi,power和data
svc [wifi|data|power] [option]

usage: svc wifi [enable|disable]
  開啟或者關閉wifi

usage: svc power stayon [true|false|usb|ac]
  true電源一直保持stay on的狀態,
  usb插上usb才保持stay on
  ac充電的時候

f)bootanimation
顯示開機動畫,在替換預設的開機動畫的時候可以用這個來調試

g)getevent & sendevent
getevent監控當前的事件,滑鼠事件,按鍵事件,拖動滑動等

# getevent
getevent
add device 1: /dev/input/event0
  name: "qwerty2"
/dev/input/event0: 0001 001e 00000001
/dev/input/event0: 0001 001e 00000000

其中/dev/input/event0是device的名字 0001是type, 001e是鍵碼, 最後一個根據type不同而不同
比如上面的倒數第二條就是按下a鍵的keydown,最後一個是按下a的keyup
具體的type,code,value的定義可以在源碼/frameworks/base/core/java/android/view/KeyEvent.java中找到

sendevent發送時間,格式和上面的一樣,需要注意的是在get中code顯示的是十六進位,而send中需要用十進位,例如

# sendevent /dev/input/event0 1 5 1
這個命令就是發送數字4的keydown訊息,所以在螢幕上就會一直列印出很多個4(因為沒有發送keyup)

h)一項常用的print message命令
dumpsy
dumpstate
logcat
dmesg
這幾條命令都整合在ddms裡面了,所以一般用的很少

3. 還有很多命令不知道怎麼用,繼續研究,完了再來更新

相關文章

聯繫我們

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