【Android】-- adb shell 命令探索

來源:互聯網
上載者:User

標籤:android開發   android shell commen   

ADB是什麼,做android開發的沒有不知道的。

window下運行cmd,輸入adb help就會列印adb都能夠做的事情,包括 adb push 。。adb pull 。。 adb devices  adb install。。。 等等。。並且一搜一大把。 


其中有一個命令叫做  adb shell,android是基於linux的,shell模式下linux的命令可是非常多的,android去掉了許多linux的命令,那麼從這寫命令裡面又能夠發現什麼寶藏呢?尋寶之旅開啟!!


首先linux的shell模式有許多命令,例如 ls cd mkdir su ps vim等等許多控制命令,這些在android上都是支援的。但是它是android的核心啊,應該有些特殊點的吧。


通過命令cd /system/bin 進入bin目錄查看一下。


# cd /system/bincd /system/bin# lslsBlobCache_testInputChannel_testInputDispatcher_testInputEvent_testInputPublisherAndConsInputReader_testLooper_testObbFile_testString8_testUnicode_testZipFileRO_testadbamapp_processapplypatchapplypatch_staticashaudioloopbmgrbootanimationbubugreportcatcheck_prereqchmodchowncmpdalvikvmdatedddebuggerddecoderdexoptdfdhcpcddmesgdumpstatedumpsysflash_imagefsck_msdosgdbjithelpergdbservergeteventgetpropgziphdidifconfigiftopimeinputinsmodinstalldioctlioniceip6tablesiptableskeystorekeystore_clikilllinkerlnloglogcatlogwrapperlslsmodlsofmediaservermkdirmonkeymountmtpdmvnandreadndcnetcfgnetdnetstatnewfs_msdosnotifyomx_testspingping6pmpppdprintenvpsqemu-propsqemudrracoonradiooptionsrebootrecordrecordvideorecoveryrenicerildrmrmdirrmmodrouterun-asschedtestschedtopscreencapscreenshotsdcardsendeventsensorserviceserviceservicemanagersetconsolesetpropsf2shshowleasesimg2imgskia_testsleepsmdstagefrightstartstopstreamsurfaceflingersvcsyncsystem_servertestid3toolboxtoptouchumountupdateruptimevdcvmstatvoldwatchpropswipe#

噢 my god 命令還是很多的嘛!

我們一般可以通過 命令 -h 來查看介紹,例如:

# am -ham -husage: am [subcommand] [options]usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]               [--R COUNT] [-S] <INTENT>       am startservice <INTENT>       am force-stop <PACKAGE>       am kill <PACKAGE>       am kill-all       am broadcast <INTENT>       am instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w]               [--no-window-animation] <COMPONENT>       am profile [looper] start <PROCESS> <FILE>       am profile [looper] stop [<PROCESS>]       am dumpheap [flags] <PROCESS> <FILE>       am set-debug-app [-w] [--persistent] <PACKAGE>       am clear-debug-app       am monitor [--gdb <port>]       am screen-compat [on|off] <PACKAGE>       am display-size [reset|MxN]       am to-uri [INTENT]       am to-intent-uri [INTENT]am start: start an Activity.  Options are:    -D: enable debugging    -W: wait for launch to complete    --start-profiler <FILE>: start profiler and send results to <FILE>    -P <FILE>: like above, but profiling stops when app goes idle    -R: repeat the activity launch <COUNT> times.  Prior to each repeat,        the top activity will be finished.    -S: force stop the target app before starting the activityam startservice: start a Service.am force-stop: force stop everything associated with <PACKAGE>.am kill: Kill all processes associated with <PACKAGE>.  Only kills.  processes that are safe to kill -- that is, will not impact the user  experience.am kill-all: Kill all background processes.am broadcast: send a broadcast Intent.am instrument: start an Instrumentation.  Typically this target <COMPONENT>  is the form <TEST_PACKAGE>/<RUNNER_CLASS>.  Options are:    -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT).  Use with        [-e perf true] to generate raw output for performance measurements.    -e <NAME> <VALUE>: set argument <NAME> to <VALUE>.  For test runners a        common form is [-e <testrunner_flag> <value>[,<value>...]].    -p <FILE>: write profiling data to <FILE>    -w: wait for instrumentation to finish before returning.  Required for        test runners.    --no-window-animation: turn off window animations will running.am profile: start and stop profiler on a process.am dumpheap: dump the heap of a process.  Options are:    -n: dump native heap instead of managed heapam set-debug-app: set application <PACKAGE> to debug.  Options are:    -w: wait for debugger when application starts    --persistent: retain this valueam clear-debug-app: clear the previously set-debug-app.am monitor: start monitoring for crashes or ANRs.    --gdb: start gdbserv on the given port at crash/ANRam screen-compat: control screen compatibility mode of <PACKAGE>.am display-size: override display size.am to-uri: print the given Intent specification as a URI.am to-intent-uri: print the given Intent specification as an intent: URI.<INTENT> specifications include these flags and arguments:    [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]    [-c <CATEGORY> [-c <CATEGORY>] ...]    [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]    [--esn <EXTRA_KEY> ...]    [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]    [--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]    [--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]    [--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]    [--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]    [--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]    [-n <COMPONENT>] [-f <FLAGS>]    [--grant-read-uri-permission] [--grant-write-uri-permission]    [--debug-log-resolution] [--exclude-stopped-packages]    [--include-stopped-packages]    [--activity-brought-to-front] [--activity-clear-top]    [--activity-clear-when-task-reset] [--activity-exclude-from-recents]    [--activity-launched-from-history] [--activity-multiple-task]    [--activity-no-animation] [--activity-no-history]    [--activity-no-user-action] [--activity-previous-is-top]    [--activity-reorder-to-front] [--activity-reset-task-if-needed]    [--activity-single-top] [--activity-clear-task]    [--activity-task-on-home]    [--receiver-registered-only] [--receiver-replace-pending]    [--selector]    [<URI> | <PACKAGE> | <COMPONENT>]Error: Unknown command: -h

雖然-h沒法識別,可還是列印出了參數的。

1、am命令是非常有用的一個命令,使用此命令可以啟動 activity, services;發送 broadcast等等。

使用執行個體:如啟動一個 Activity:

格式:adb shell am start -n 包名/包名+類名(-n 類名,-a action,-d date,-m MIME-TYPE,-c category,-e 擴充資料,等)。 

執行個體1:C:\Users\Administrator>adb shell am start -n com.android.camera/.CameraStarting: Intent { cmp=com.android.camera/.Camera } 

執行個體2:(帶extra 的 intent)C:\Users\Administrator>adb shell am start -n com.android.camera/.Camera -e abc helloStarting: Intent { cmp=com.android.camera/.Camera (has extras) }其中 extra 的 key 為 abc ,value 為字串 "hello" 

還可以發送命令類比手機低電環境:

執行個體:adb shell am broadcast -a android.intent.action.BATTERY_CHANGED --ei "level" 3 --ei "scale" 100

2、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]: []

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

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

聯繫我們

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