你好 安卓外文翻译资料

 2022-08-22 10:08

Hello Android

Chapter 1

Quick Start

Android combines the ubiquity of cell phones, the excitement of open source software, and the corporate backing of Google and other Open Handset Alliance members like Intel, TI, T-Mobile, and NTT DoCoMo. The result is a mobile platform you canrsquo;t afford not to learn.

Luckily, getting started developing with Android is easy. You donrsquo;t even need access to an Android phone—just a computer where you can install the Android SDK and phone emulator.

In this chapter, Irsquo;ll show you how to get all the development tools installed, and then wersquo;ll jump right in and create a working application: Androidrsquo;s version of “Hello, World.”

1.1 Installing the Tools

The Android software development kit (SDK) works on Windows, Linux, and Mac OS X. The applications you create, of course, can be deployed on any Android devices.

Before you start coding, you need to install Java, an IDE, and the Android SDK.

Java 5.0

First you need a copy of Java. All the Android development tools require it, and programs you write will be using the Java language. JDK 5 or 6 is required.

Itrsquo;s not enough to just have a runtime environment (JRE); you need the full development kit. I recommend getting the latest Sun JDK 6.0 update from the Sun download site. Mac OS X users should get the latest version of Mac OS X and the JDK from the Apple website. To verify you have the right version, run this command from your shell window. Herersquo;s what I get when I run it:

C:gt; java -version

java version '1.6.0_13'

Java(TM) SE Runtime Environment (build 1.6.0_13-b03)

Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

You should see something similar, with version “1.6.something” or later.

Ecplise

Next, you should install a Java development environment if you donrsquo;t have one already. I recommend Eclipse, because itrsquo;s free and because itrsquo;s used and supported by the Google developers who created Android.

If you donrsquo;t want to use Eclipse (therersquo;s always one in every crowd), support for other IDEs such as NetBeans and JetBrains IDEA is available from their respective communities. Or if yoursquo;re really old-school, you can forgo an IDE entirely and just use the command-line tools.

The minimum version of Eclipse is 3.3.1, but you should always use whatever is the most up-to-date production version. Note that you need more than just the standard Eclipse SDK “classic” platform. Go to the Eclipse downloads page, and pick “Eclipse IDE for Java Developers.” Follow the directions there for downloading, unpacking, and installing Eclipse into a suitable location (like C:Eclipse on Windows).

Android

Next, download the latest Android SDK from Google. The Android download page4 has packages for Windows, Mac OS X, and Linux. After downloading the package thatrsquo;s right for you, unpack the .zip file to a convenient directory (for example, C:Google).

By default, the SDK will be expanded into a subdirectory like android-sdk-windows-1.5_r2. This is your SDK install directory; make a note of the full path so you can refer to it later.

Figure 1.1: Installing the Android Development Toolkit

No special install program is needed but I do recommend you add the SDKrsquo;s bin directory to your PATH. The next step is to start Eclipse and configure it.

Ecplise Plug-In

To make development easier, Google has written a plug-in for Eclipse called the Android Development Toolkit (ADT). To install the plug-in, follow these steps (note these directions are for Eclipse 3.4—different versions may have slightly different menus and options):

  1. Start Eclipse, and select Help gt; Software Updates....
  2. Click the Available Software tab if itrsquo;s not already selected.
  3. Click the Add Site... button.
  4. Enter the location of the Android update site: https://dl-ssl.google.com/android/eclipse/. If you have trouble with this address, try using http in the location instead of https.

Once yoursquo;ve filled it out, the dialog box should look like Figure 1.1.Click OK.

  1. The Android site should now appear in the Available Software view. Select the checkbox next to it, and then click Install.... If you get an error message, then you may not have the right version of Eclipse. I strongly recommend using either the prebuilt Eclipse IDE for Java or the Eclipse IDE for Java EE Development packages, version 3.4 or newer.

If you have a custom install of Eclipse, then to use the Android editors you will also need to install the Web Standard Tools (WST) plug-in and all its prerequisites.

See the Web Tools platform home page for more details and download links. These are already built into the recommended packages mentioned earlier.

  1. Click Next, accept the license agreements, and then click Finish to start the download and install process.
  2. Once the install is done, restart Eclipse.
  3. When Eclipse comes back up, you may see a few error messages because you need to tell it where the Android SDK is located. Select Window gt; Preferences gt; Android (Eclipse gt; Preferences on Mac OS X), and enter the SDK install directory you noted earlier. Click OK.

Whew! Luckily, you have to do that only once (or at least once every time a new version of ADT or Eclipse comes out). Now that everything is installed, itrsquo;s time to write your first program.

1.2 Creating Your First Program

ADT comes with a built-in example program, or template, that wersquo;re going to use to create a simple “Hello, Android” program in just a few seconds. Get your stopwatch ready. Ready? Set? Go!

Select File gt; New gt; Project... to open the New Project dialog box. Then se

剩余内容已隐藏,支付完成后下载完整资料


你好 安卓

第一章 快速入门

Android将手机的普及性、开源软件的活跃性,以及谷歌和其他开放后手机联盟成员(如英特尔、TI、T-Moblie和NTT DoCoMo)的集合支持完美地结合在一起。最终的成果就是一个你不可不学的移动平台。

幸运的是,开发简单的Android程序很容易,甚至无需使用Android手机,只要准备一台可安装Android SDK和手机模拟器的计算机就可以了。

本章介绍如何安装所有的开发工具,然后演示如何创建一个可运行的应用程序:Android版本的“Hello,World”。

1.1安装工具

1.1.1 Java 5.0

首先需要安装Java,所有的Android开发工具都需要它,编写Android程序也需要使用Java语言。需要使用JDK5或6。

是由一个运行环境(JRE)还不够,还需要完整的开发包。我建议从Sun下载网站下载并安装最新的Sun JDK 6.0更新。Mac OS X用户应该从苹果公司的网站下载并安装最新版本的Mac OS X和JDK。

要确定已安装的版本是否正确,可以在命令行窗口中运行以下命令。下面是运行该命令时显示的结果:

C:gt; java -version

java version '1.6.0_13'

Java(TM) SE Runtime Environment (build 1.6.0_13-b03)

Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

在计算机上运行该命令后,你应该能看到类似的输出内容,其中版本应该是“1.6.其他数字”或更高。

1.1.2 Ecplise

接下来应该安装Java开发环境(如果计算机上没有该环境)。我建议安装Ecplise,因为这个软件是免费的,并且创建Android的谷歌开发人员也使用它并且支持它。

如果不想使用Ecplise(肯定有人不想用),也可以使用其他IDE,如果NetBeans和JetBrainsIDEA(相应的社区都有提供)。如果你是个很守旧的人,可以完全忘记IDE,仅适用命名行工具。

必须使用3.3.1以上的Ecplise,但是应该始终使用最新的可用的版本。注意,所需要的不仅仅只是标准的Ecplise SDK“经典”平台请访问Ecplise下载页,然后选择Ecplise IDE for Java Developers。按照该页上的说明下载该Ecplise,然后进行解压并在合适的位置安装(例如在Windows计算机上是C:Ecplise)Ecplise。

1.1.3 Android

然后,从谷歌网站下载最新的Android SDK。Android下载页上提供了用于Windows、Mac OS X和Linux的软件包。下载合适的软件包之后。将.zip文件解压到适当的目录中(例如C:Google)。

默认的情况下,会将该SDK展开到一个子目录中,如androidsdk-windows-1.6_r1。这是SDK的安装目录。记下该目录的完整路径,便于日后参考。

不需要使用特殊的安装程序,下一步就是启动Ecplise并对其进行配置。

1.1.4 Ecplis插件

为了让开发过程等轻松,谷歌还编写了一款为ADT(Android Development Toolkit,Android开发工具包)的Ecplise插件。想要安装该插件,请执行以下步骤(注意,这些步骤说明适用于Ecplise3.4,如果使用其他Ecplise版本,那么菜单和选项可能稍有不同)。

(1)启动Ecplise,然后选择Help gt; Software Updates...。

(2)单击Avaiable Software选项卡(如果尚为选中该选项卡)。

(3)单击Add Sitehellip;按钮。

(4)输入Android更新站点的位置:: https://dl-ssl.google.com/android/eclipse/

输入完成后,该对话框应该如图1-1所示。单击OK按钮。

(5)现在,该Android站点应该出现在Available Software视图中。选中该站点旁边的复选框,然后点击Installhellip;。如果出现错误消息,原因可能是Ecplise的版本不对。我强烈建议使用预编译的Ecplise IDE for Java或者Ecplise IDE for Java EE开发软件包3.4以上版本。

图1-1 安装Android开发工具包

如果安装Ecplise时使用了自定义安装方法,那么要想使用Android编译器,还需要安装WST(Web Standard Tools,Web标准工具)插件及必须的其他插件。

参见Web工具平台主页,了解详细信息和下载链接。这些内容已经内置在前面建议使用的软件包中。

(6)单击Finish开始下载和安装过程。

(7)安装完成后,重新启动Ecplise。

(8)Ecplise启动后你可能会看见几条错误的消息,因此此时需要告诉它AndroidSDK位于何处。选择Window gt; Preferences gt; Android ,然后输入你在前面记下的SDK安装目录。单击OK按钮。

幸运的是,上述步骤只需执行一次(或者说每次安装新版本的ADT或者Ecplise后至少需要执行上述步骤一次)。现在,所需的内容都已经安装好,可以编写第一个程序来。

1.2 创建第一个程序

ADT附带了一个内置的实例程序,及模板,我们要使用这个模板快速地创建一个简单的“Hello,Android”程序。准备好秒表。准备就绪?归零?开始计时!

选择File gt; New gt; Android Project,打开New Project对话框。然后选择Android gt; Android Project,单击Next按钮。

输入如下信息:

Project name: HelloAndroid

Build Target: Android 1.5

Application name: Hello, Android

Package name: org.example.hello

Create Activity: Hello

输入完成后,对话框应该如图1-2所示。

图1-2 新建Android项目

单击Finish按钮,Android插件将创建该项目,并在该项目中添加一些默认的文件。Ecplise将会生成该项目并将该项目内容打包,然后就可以执行该项目了。

程序的编写已经完成,现在剩下的就是运行该程序了。

1.3 在模拟器上运行程序

要想运行Android程序,请进入Package Explorer窗口,右键单击HelloAndroid项目,然后选择Run As gt; Android Application。此时会打开Android模拟器窗口并启动Android操作系统。第一次执行上诉操作时,可能需要一两分钟的时间,所以请耐心等待/如果出现错误消息,显示应用程序没有响应,请选择继续等待的选项。

模拟器窗口打开后,Ecplise会向模拟器发送要执行的程序的一个副本。然后会出现应用程序界面,并且运行“Hello,Android”程序(参见图1-3)。这就够了!恭喜你完成了第一个Android程序。

图1-3 正在运行的“Hello,Android”程序

1.4 在手机上运行程序

开发期间,在实际的设备(如T-Mobile G1)上运行Android程序与在模拟器上运行该程序的效果几乎相同。需要做的就是用USB电缆连接手机与计算机,并安装一个特殊的设备驱动程序。如果模拟器窗口已打开,请将其关闭。只要将手机与计算机相连,应用程序就会在手机上加载并运行。

在向外界发布应用程序之前,需要获得一个加密密钥并使用该密钥签名软件包。网上提供了有关过程的详细说明。支付少量的注册费后,就可以将你的程序上传到Android Market。让你的应用程序出现在Market上是你的最终目标。世界各地数百万计的用户都可在此看到你的工作成果,对你的程序进行评级,甚至掏钱购买它。

1.5 快速阅读指南

有了Ecplise插件,只需几秒钟即可创建一个最简单的Android程序。在第3章中,我们将通过一个实习的应用程序(数独游戏)来扩展上面的简单程序。在很多章中我们都会使用这个游戏实例演示Android API的使用。

但是在深入了解这个示例之前,应该花谢时间阅读第二章。当你真正了解了像活动和生命周期这样的基本概念时,理解其他内容也就很容易了。

虽然使用Ecplise开发Android程序只是多种选择中的一种,但是我强烈建议使用这种方法。如果你以前从为使用过Ecplise,可能需要买本书来看看,如Ecplise IDE PocketGuide[Bur05]。

第二章 基本概念

现在,读者已经了解了Android是什么,接下来我们再看看它是如何工作的。你可能对Android的某些部分很熟悉,如Linux内核、OpenGL和SQL数据库,但对其他部分可能还一无所知,如Android中应用程序生命周期的概念。

要编写出功能良好的Android应用程序,需要很好地理解本章介绍的这些基本概念。所以,人哦过你只想阅读本书中的一章,则非本章莫属。

2.1 Android的系统架构

我们首先看看Android的总体系统架构——组成Android开源软件栈的关键层和组件。图2-1展示了完整的Android系统构架图,请读者自己研究一下这张图,明天我们要考你的哦。

图2-1 Android系统构架

图中的每一层都使用下面各层所提供的服务。以下几节主要介绍Android中的各个层(从最下面的层开始)。

2.1.1 Linux内核

Android构建在一个稳定且得到广泛认可的基础之上:Linux内核。1991年,还是赫尔辛基大学学生的Linus Torvalds开发了Linux内核。现在,Linux可以说是无所不在,从手表到超级计算机中都能找到它的身影。Linux为Android提供了硬件抽象层,以便将来把Android移植到更多的平台上。

从内部来看,Android使用Linux完成其内存管理、进程管理、网络和其他操作系统服务工作。Android手机用户永远也不会看到Linux,程序也不会直接进行Linux调用。但是作为开发人员,你需要知道Linux在Android中用途。

开发期间需要的某些使用程序要和Linux打交道。例如,adb shell命令将打开一个Linux命令行窗口,从中可以输入要在设备上运行的其他命令。例如,可以通过这个命令行窗口来检查Linux文件系统、查看活动的进程等。

2.1.2 本机库

Linux内核层上面的一层中包含了Android的本机库。这些共享库都是用C或C 语言编写的,并且针对电话使用的特定硬件构架进行了编译,并已由手机制造商预先安装到手机中。

其中最重要的一些库包括下面5个部分。

界面管理器(Surface Manager):Android使用于Vista或Compiz类似的组合管理器,但是它要更简单一些。它并不是将显示内容直接绘制到屏幕缓冲区中,而是将绘制命令传递给屏幕外的位置,然后将该位图与其他位图组合起来,形成用户看到的显示内容。这种方法允许系统实现所有有趣的效果,如透明的窗口和奇特的过渡效果。

2D和3D图形:使用Android时,二维和三维元素可结合到一个用户界面中。库将使用3D硬件(如果设备上有的话)或者快速软件渲染器(如果没有3D硬件设备)。参见第4章和第10章。

媒体编解码器:Android可播放视频内容,并可用各种格式录制和播放音频,这些格式包括AAC、AVC(H.264)H.263、MP3和MPEG-4。参见第5章中县官的示例。

SQL数据库:Android提供了轻量级的SQLite数据引擎,Firefox和苹果的iPhone中使用的也是该数据引擎。使用该引擎可在应用程序中持续存储。参见第9章中相关的示例。

浏览器引擎:为保证快速显示HTML内容,Android使用了WebKit库。Google Chrome浏览器、苹果的Safari浏览器、苹果iPhone和诺基亚的S60平台都使用了该引擎。参见第7章中相关的示例。

2.1.3 And

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[498314],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。