本文为原创,如需转载,请注明作者和出处,谢谢!
本文为新书《Android/OPhone 开发完全讲义》的内容连载。《Android/OPhone开发完全讲义》一书现已出版,敬请关注。
购 买:互动网(china- pub)
《Android/OPhone开发完全讲义》目录

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:黑体; panose-1:2 1 6 9 6 1 1 1 1 1; mso-font-alt:SimHei; mso-font-charset:134; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-2147482945 953122042 22 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:"/@黑体"; panose-1:2 1 6 9 6 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-2147482945 953122042 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; line-height:15.7pt; mso-pagination:none; mso-layout-grid-align:none; font-size:10.5pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:宋体;} h3 {mso-style-name:"标题 3/,/(分步/)/,/(小节/)"; mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"标题 3 Char"; mso-style-next:正文; margin-top:15.0pt; margin-right:0cm; margin-bottom:15.0pt; margin-left:0cm; text-align:justify; text-justify:inter-ideograph; line-height:15.7pt; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:3; mso-layout-grid-align:none; font-size:13.0pt; mso-bidi-font-size:10.5pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:黑体; font-weight:normal;} span.3Char {mso-style-name:"标题 3 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 3/,/(分步/)/,/(小节/)"; mso-ansi-font-size:13.0pt; mso-bidi-font-size:10.5pt; font-family:"Arial","sans-serif"; mso-ascii-font-family:Arial; mso-fareast-font-family:黑体; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial;} p.a, li.a, div.a {mso-style-name:编程步骤; mso-style-unhide:no; mso-style-link:"编程步骤 Char"; margin-top:0cm; margin-right:0cm; margin-bottom:0cm; margin-left:21.0pt; margin-bottom:.0001pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:0cm; mso-para-margin-left:2.0gd; mso-para-margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; line-height:13.0pt; mso-pagination:none; layout-grid-mode:char; background:#E0E0E0; mso-layout-grid-align:none; font-size:9.0pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:黑体;} span.Char {mso-style-name:"编程步骤 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:编程步骤; mso-ansi-font-size:9.0pt; mso-bidi-font-size:9.0pt; font-family:"Arial","sans-serif"; mso-ascii-font-family:Arial; mso-fareast-font-family:黑体; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial; background:#E0E0E0;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} -->
上一篇:Android SDK中常用命令行工具(一)
一、 P C与模拟器或真机交换文件(adb pull和adb push)
在开发阶段或其他原因,经常需要将PC上的文件复制到模拟器或真机上,或将模拟机和真机上的文件复制到PC上。使用adb pull和adb push命令可以很容易完成这个工作。例如,下面的命令将真机的SD卡根目录下的camera.jpg文件复制到PC的当前目录,取名为picture.jpg。又把picture.jpg文件复制到真机的SD卡根目录,取名为abc.jpg。
从真机上复制文件到PC
adb -s HT9BYL904399 pull /sdcard/camera.jpg picture.jpg
从PC复制到文件到真机
adb -s HT9BYL904399 push picture.jpg /sdcard/abc.jpg
如果读者安装了ADT,可以通过DDMS透视图的【File Explorer】视图右上方的几个按钮方便地从模拟器或真机上导入、导出和删除文件。
二、 Shell命令
由于Android是基于Linux内核的操作系统。因此,在Android上可以执行Shell命令。虽然在手机上提供了可以输入命令的Shell程序,但在手机上输入程序实在是不方便。为了更方便地在模拟器或手机上执行Shell命令。可以使用如下的命令在PC上进入Shell控制台。
adb -s HT9BYL904399 shell
Shell控制台的提示符是一个井号(#)。进入Shell后,输入cd system/bin命令,再输入ls命令,可以看到当前Android系统支持的命令文件,如图1所示。读者可以根据实际情况使用相应的命令。

图1 <!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; line-height:15.7pt; mso-pagination:none; mso-layout-grid-align:none; font-size:10.5pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:宋体;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} --> Shell控制台
<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:黑体; panose-1:2 1 6 9 6 1 1 1 1 1; mso-font-alt:SimHei; mso-font-charset:134; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-2147482945 953122042 22 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:"/@黑体"; panose-1:2 1 6 9 6 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-2147482945 953122042 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; line-height:15.7pt; mso-pagination:none; mso-layout-grid-align:none; font-size:10.5pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:宋体;} h3 {mso-style-name:"标题 3/,/(分步/)/,/(小节/)"; mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"标题 3 Char"; mso-style-next:正文; margin-top:15.0pt; margin-right:0cm; margin-bottom:15.0pt; margin-left:0cm; text-align:justify; text-justify:inter-ideograph; line-height:15.7pt; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:3; mso-layout-grid-align:none; font-size:13.0pt; mso-bidi-font-size:10.5pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:黑体; font-weight:normal;} span.3Char {mso-style-name:"标题 3 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 3/,/(分步/)/,/(小节/)"; mso-ansi-font-size:13.0pt; mso-bidi-font-size:10.5pt; font-family:"Arial","sans-serif"; mso-ascii-font-family:Arial; mso-fareast-font-family:黑体; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial;} p.a, li.a, div.a {mso-style-name:编程步骤; mso-style-unhide:no; mso-style-link:"编程步骤 Char"; margin-top:0cm; margin-right:0cm; margin-bottom:0cm; margin-left:21.0pt; margin-bottom:.0001pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:0cm; mso-para-margin-left:2.0gd; mso-para-margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; line-height:13.0pt; mso-pagination:none; layout-grid-mode:char; background:#E0E0E0; mso-layout-grid-align:none; font-size:9.0pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:黑体;} span.Char {mso-style-name:"编程步骤 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:编程步骤; mso-ansi-font-size:9.0pt; mso-bidi-font-size:9.0pt; font-family:"Arial","sans-serif"; mso-ascii-font-family:Arial; mso-fareast-font-family:黑体; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial; background:#E0E0E0;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} -->
三、 创建、删除和浏览AVD设备(android)
在这里将介绍直接使用android命令来建立和删除AVD设备。建立AVD设备的命令如下:
android create avd -n myandroid1.5 -t 2
其中myandroid1.5表示AVD设备的名称,该名称可以任意设置,但不能和其他AVD设备冲突。-t 2中的2指建立Android 1.5的AVD设备。1表示Android 1.1的AVD设备。以此类推。目前最新的Android 2.1应使用-t 6来建立AVD设备。在执行完上面的命令后,会输出如下的信息来询问是否继续定制AVD设备。
Android 1.5 is a basic Android platform.
Do you wish to create a custom hardware profile [no]
如果读者不想继续定制AVD设备,直接按回车即可。如果想定制AVD设备,输入y,然后按回车。系统会按步提示该如何设置。中括号内是默认值,如果某个设置项需要保留默认值,直接按回车即可。如果读者使用的是Windows XP,默认情况下AVD设备文件放在如下的目录。
C:/Documents and Settings/Administrator/.android/avd
如果想改变AVD设备文件的默认存储路径,可以使用-p命令行参数,命令如下:
android create avd -n myandroid1.5 -t 2 -p d:/my/avd
删除AVD设备可以使用如下的命令。
android delete avd -n myandroid1.5
通过下面的命令可以列出所有的AVD设备。
android list avds
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-16915591-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();