【Android】-- adb shell 命令探索

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/bin
cd /system/bin
# ls
ls
BlobCache_test
InputChannel_test
InputDispatcher_test
InputEvent_test
InputPublisherAndCons
InputReader_test
Looper_test
ObbFile_test
String8_test
Unicode_test
ZipFileRO_test
adb
am
app_process
applypatch
applypatch_static
ash
audioloop
bmgr
bootanimation
bu
bugreport
cat
check_prereq
chmod
chown
cmp
dalvikvm
date
dd
debuggerd
decoder
dexopt
df
dhcpcd
dmesg
dumpstate
dumpsys
flash_image
fsck_msdos
gdbjithelper
gdbserver
getevent
getprop
gzip
hd
id
ifconfig
iftop
ime
input
insmod
installd
ioctl
ionice
ip6tables
iptables
keystore
keystore_cli
kill
linker
ln
log
logcat
logwrapper
ls
lsmod
lsof
mediaserver
mkdir
monkey
mount
mtpd
mv
nandread
ndc
netcfg
netd
netstat
newfs_msdos
notify
omx_tests
ping
ping6
pm
pppd
printenv
ps
qemu-props
qemud
r
racoon
radiooptions
reboot
record
recordvideo
recovery
renice
rild
rm
rmdir
rmmod
route
run-as
schedtest
schedtop
screencap
screenshot
sdcard
sendevent
sensorservice
service
servicemanager
setconsole
setprop
sf2
sh
showlease
simg2img
skia_test
sleep
smd
stagefright
start
stop
stream
surfaceflinger
svc
sync
system_server
testid3
toolbox
top
touch
umount
updater
uptime
vdc
vmstat
vold
watchprops
wipe
#

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

我们一般可以通过 命令 -h 来查看介绍,例如:

# am -h
am -h
usage: 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 activity

am 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 heap

am set-debug-app: set application <PACKAGE> to debug.  Options are:
    -w: wait for debugger when application starts
    --persistent: retain this value

am 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/ANR

am 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 下的数据

【Android】-- adb shell 命令探索,布布扣,bubuko.com

时间: 2024-08-05 19:35:02

【Android】-- adb shell 命令探索的相关文章

Android Adb Shell命令详解(带DOS、Linux命令)

在Android应用程序开发过程中,经常用到adb shell,这里对常规命令做一个简单的总结. 内容包括Dos.Linux.Shell三块(通过查阅书籍及网络资料所得). 1.首先看Windows DOS下的命令 cd——改变当前目录 dir——显示文件夹内容 md——建立子目录 copy——拷贝文件 move——移动文件 del——删除文件 cls——清屏 attrib——显示文件的(文件)属性 2.接下来给出Linux下常规命令 cd——改变当前目录 pwd——查看当前所在目录完整路径 l

android adb shell 命令大全

1. 显示系统中全部Android平台: android list targets 2. 显示系统中全部AVD(模拟器): android list avd 3. 创建AVD(模拟器): android create avd --name 名称 --target 平台编号 4. 启动模拟器: emulator -avd 名称 -sdcard ~/名称.img (-skin 1280x800) 5. 删除AVD(模拟器): android delete avd --name 名称 6. 创建SDC

Android 常用adb shell 命令(转)

调试Android程序有时需要adb shell 命令,adb全称Android Debug Bridge ,就是起到调试桥的作用. 通过adb我们可以在Eclipse中通过DDMS来调试Android程序,说白了就是debug工具.adb通过监听Socket TCP 5554等端口让IDE和Qemu通讯. 默认情况下当我们运行Eclipse时adb进程就会自动运行.adb是一个C/S模式的程序,由三个部分组成:a client,a server and a daemon. 其中client和s

Android 执行 adb shell 命令

Android 执行Adb shell 命令大多需要root权限,Android自带的Runtime. getRuntime().exec()容易出错,在网上找到了一个执行adb shell命令的类 代码如下: /**检查手机是否存在root权限,发送一些消息*/package com.dx.superbar.util; import java.io.DataOutputStream;import java.io.File;import java.io.FileOutputStream;impo

adb shell 命令详解,android

http://www.miui.com/article-275-1.html http://noobjava.iteye.com/blog/1914348 adb shell 命令详解,android 博客分类: android 常用:1.进入模拟器的shell模式 :  adb shell 2.安装应用程序:  adb install -r 应用程序.apkadb installadb install <apk文件路径> :这个命令将指定的apk文件安装到设备上adb install  -r

【android】android 常用adb 和 adb shell 命令

db是SDK自带的工具,可实现桥接功能:adb shell 可以与手机系统建立交互,是基于andoid Linux系统下的操作 ADB常用命令: 1. 查看设备         adb  devices 这个命令是查看当前连接的设备, 连接到计算机的android设备或者模拟器将会列出显示 2. 安装软件 adb  install <apk文件路径> 这个命令将指定的apk文件安装到设备上       参数“-r”,它是更新安装的意思,       参数 -s ,安装到sdcard.     

Android 常用adb shell 命令

调试Android程序有时需要adb shell 命令,adb全称Android Debug Bridge ,就是起到调试桥的作用.通过adb我们可以在Eclipse中通过DDMS来调试Android程序,说白了就是debug工具.adb通过监听Socket TCP 5554等端口让IDE和Qemu通讯.默认情况下当我们运行Eclipse时adb进程就会自动运行.adb是一个C/S模式的程序,由三个部分组成:a client,a server and a daemon.其中client和serv

android adb常用命令

1.adb--- 截取屏幕的命令  :adb shell screencap -p | sed 's/\r$//' > outputs.png 2.jni ---命令    :$NDK/ndk-build 3. adb 启动程序:adb shell am start -n 包名/程序Activity类的类名(main) adb 安装程序: adb install  + 路径 adb 卸载程序 :adb uninstall +包名 adb 调试:  adb connect ip 地址 adb 断开

adb shell命令后出现error: device not found错误提示

在cmd中输入adb shell进入linux shell环境前,需要把android模拟器打开(本文都是针对模拟器而言,并非真机).如果启动好了模拟器,且输入adb shell命令后出现error: device not found错误提示,则可以杀掉adb进程然后重新启动该进程,在cmd中输入如下命令: adb kill-server adb start-server 注意:这里着重注意,要想adb shell命令执行成功,必须要同时打开android模拟器. 这是执行成功后,以root权限