ADB shell

首先android是一个开源操作系统,并基于linux开源操作系统,Android继承了Linux的特性。

1、什么是adb?
adb的全称为Android Debug Bridge,是一个调试工具。借助它,开发人员可以完成很多需要再手机端操作所需完成的事情。

2. 什么是shell?

    操作系统运行的本身其实并不需要人来控制。但人需要告诉操作系统做什么,这个交互程序,就被称为shell。
  这里我把shell分成三种:

  •图形shell:
  这种shell有很多种,windows的Explorer.exe,Linux的Gnome/Kde ....
  在windows看到的桌面,开始菜单,也是一种图形shell
  •终端Shell:
  终端Shell除了windows下的cmd.exe已经弱化到残废的地步,其他的操作系统都是比较强悍的;
  终端Shell最大的特点是字符操作,没有图形,试想,如果你的操作系统显卡驱动崩溃了,绘图功能不举了,这就是最后的稻草了。
  事实上,几乎所有的显卡驱动都是在终端Shell下编写,然后用于绘制图形Shell....
  特别是在linux\mac\android下面,终端Shell是灰常的强大的。
  如:bash\zsh\....
  •其他Shell:
3.adb 常用命令 http://blog.csdn.net/yunnywu/article/details/7975451

(1)Adb shell  直接进入adb shell模式

(2)Adb push 电脑端文件 手机上文件 将电脑端的文件拷贝到手机上

(3)adb pull 手机上文件 电脑端文件 将手机上文件复制到电脑端

【复制】

1. 查看设备 
        adb  devices
  这个命令是查看当前连接的设备, 连接到计算机的android设备或者模拟器将会列出显示 

2. 安装软件 
  adb  install <apk文件路径> 
  这个命令将指定的apk文件安装到设备上
       参数“-r”,它是更新安装的意思,
       参数 -s ,安装到sdcard. 
       如: adb install com.sina.weibo.apk	

3. 卸载软件 
  adb  uninstall <包名>  
        如果加 -k 参数,为卸载软件但是保留配置和缓存文件.
        如: adb uninstall com.sina.weibo.apk	

4. 登录设备shell 
  adb  shell 
  adbshell <command命令> 
  这个命令将登录设备的shell. 
  后面加<command命令>将是直接运行设备命令, 相当于执行远程命令
        如:	adb  shell cat /proc/kmsg 

5. 从电脑上发送文件到设备 
  adb push <本地路径> <远程路径> 
  用push命令可以把本机电脑上的文件或者文件夹复制到设备(手机)
        如: adb push /local/build.prop  /system/build.prop

6. 从设备上下载文件到电脑 
  adb  pull <远程路径> <本地路径> 
  用pull命令可以把设备(手机)上的文件或者文件夹复制到本机电脑
        如: adb  /system/build.prop  /local/

7. 同步更新 
         adb sync [ <directory> ]
         如果不指定目录,将同时更新 /data 和  /system/
         如: adb sync /data/

8. 显示帮助信息 
  adb  help 
  这个命令将显示帮助信息

9.  重新挂载
        adb  remount
        重新挂载系统  分区 用于读写
       
10.   启 動和关閉
        adb start-server             - ensure that there is a server running
        adb kill-server              - kill the server if it is running

11. 重启设备
         adb reboot [bootloader|recovery]      - reboots the device, optionally into the bootloader or recovery program


12. 查看Log 
     	[adb] logcat [<option>] ... [<filter-spec>] ..
      	-b <buffer> 加载一个可使用的日志缓冲区供查看,比如event 和radio . 默认值是main 。具体查看Viewing 	Alternative Log Buffers. 
 	-c 清楚屏幕上的日志. 
 	-d 输出日志到屏幕上. 
 	-f <filename> 指定输出日志信息的<filename> ,默认是stdout . 
 	-g 输出指定的日志缓冲区,输出后退出. 
	 -n <count> 设置日志的最大数目<count> .,默认值是4,需要和 -r 选项一起使用。 
	 -r <kbytes> 每<kbytes> 时输出日志,默认值为16,需要和-f 选项一起使用. 
	 -s 设置默认的过滤级别为silent. 
 	-v <format> 设置日志输入格式,默认的是brief 格式

	where <tag> is a log component tag (or * for all) and priority is:
 	 V    Verbose
 	 D    Debug
 	 I    Info
 	 W    Warn
 	 E    Error
 	 F    Fatal
 	 S    Silent (supress all output)

	'*' means '*:d' and <tag> by itself means <tag>:v


13、查看bug报告:
	 adb bugreport 




常用adb shell命令:

1.  按键事件 
         input text <string>   input a string to device
         input keyevent <event_code>   send a Key Event to device
        如: adb shell input keyevent 26      (PowerKey)

2.  am命令
           am start  <INTENT> : start an Activity
           如 : 
           am start -n com.android.calculator/com.android.calculator2.Calculator
           	
           am broadcast <INTENT> 
 
           am startservice <INTENT>
           am force-stop <PACKAGE>
           am kill <PACKAGE> 
           am kill-all
           am broadcast <INTENT>

                 "<INTENT> specifications include these flags and arguments:\n" +
                "    [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]\n" +
                "    [-c <CATEGORY> [-c <CATEGORY>] ...]\n" +
                "    [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]\n" +
                "    [--esn <EXTRA_KEY> ...]\n" +
                "    [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]\n" +
                "    [--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]\n" +
                "    [--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]\n" +
                "    [--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]\n" +
                "    [--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]\n" +
                "    [--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]\n" 
                "    [-n <COMPONENT>] [-f <FLAGS>]\n" +
                "    [--grant-read-uri-permission] [--grant-write-uri-permission]\n" +
                "    [--debug-log-resolution] [--exclude-stopped-packages]\n" +
                "    [--include-stopped-packages]\n" +
                "    [--activity-brought-to-front] [--activity-clear-top]\n" +
                "    [--activity-clear-when-task-reset] [--activity-exclude-from-recents]\n" +
                "    [--activity-launched-from-history] [--activity-multiple-task]\n" +
                "    [--activity-no-animation] [--activity-no-history]\n" +
                "    [--activity-no-user-action] [--activity-previous-is-top]\n" +
                "    [--activity-reorder-to-front] [--activity-reset-task-if-needed]\n" +
                "    [--activity-single-top] [--activity-clear-task]\n" +
                "    [--activity-task-on-home]\n" +
                "    [--receiver-registered-only] [--receiver-replace-pending]\n" +
                "    [--selector]\n" +
                "    [<URI> | <PACKAGE> | <COMPONENT>]\n"

 	更多詳细用法请见am 使用帮助.

启动一个 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/.Camera
Starting: Intent { cmp=com.android.camera/.Camera }
 
实例2:(带extra 的 intent)
C:\Users\Administrator>adb shell am start -n com.android.camera/.Camera -e abc hello
Starting: Intent { cmp=com.android.camera/.Camera (has extras) }

其中 extra 的 key 为 abc ,value 为字串 "hello"
 os.system("adb shell am start -a android.intent.category.LAUNCHER com.dingsns.start/com.dingsns.start.ui.home.StartActivity") #启动星瞳直播

3. pm 命令
             pm list packages    
		-f: see their associated file
		-s: filter to only show system packages
		-3 ilter to only show third party packages
	pm list packages [-f] [-d] [-e] [-s] [-e] [-u] [FILTER]");
 	pm list permission-groups
	pm list permissions [-g] [-f] [-d] [-u] [GROUP]");
	pm list instrumentation [-f] [TARGET-PACKAGE]");
 	pm list features
	pm list libraries
	pm path PACKAGE
	pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH
	pm uninstall [-k] PACKAGE
 	pm clear PACKAGE
	pm enable PACKAGE_OR_COMPONENT
	pm disable PACKAGE_OR_COMPONENT
	pm disable-user PACKAGE_OR_COMPONENT
	pm set-install-location [0/auto] [1/internal] [2/external]
	pm get-install-location
	
	更多詳细用法,请见pm使用帮助.

4. dumpsys
	dumpsys activit
		dumpsys activity intents
		dumpsys activity broadcasts
		dumpsys activity providers
		dumpsys activity services
		dumpsys activity activities
		dumpsys activity processes

	dumpsys window
		dumpsys window windows
		dumpsys window tokens
		dumpsys window sessions
		dumpsys window policy
		dumpsys window input

	dumpsys statusbar 
	dumpsys notification
	dumpsys package  [<PACKAGE> ]
	dumpsys location
	dumpsys alarm
	dumpsys connectivity
	dumpsys wifi
	…....等等
	

5. ime	输入法管理       	
     ime list [-a] [-s]
	list command prints all enabled input methods
	-s option to see only a single summary line of each.
	-a option to see all input method

	ime enable ID
	ime disable ID
	ime set ID
posted @ 2016-12-19 16:01  青柠111  阅读(2346)  评论(0编辑  收藏  举报