Application Fundamentals应用基础

Application Fundamentals应用基础

Android applications are written in the Java programming language. Android应用是用Java 语言写的

  • The Android SDK tools compile the code—along with any data and resource files—into an Android package, an archive file with an .apk suffix.

  • Android SDK工具编译代码---及与代码一起的任意数据,资源文件---到一个包中,一个.apk后缀的归档文件.

    All the code in a single .apk file is considered to be one application and is the file that Android-powered devices use to install the application.

  • 所有代码都在单个.apk文件中,当成一个应用,这个文件就是通常安装在Android设备中的应用

  • Once installed on a device, each Android application lives in its own security sandbox:一旦安装到了一个设备,每个应用生存在它自己的安全沙箱中

    • The Android operating system is a multi-user Linux system in which each application is a different user.
    • 一个Android系统是一个多用户的Linux系统,其中的每个应用都是一个不同的用户
    • By default, the system assigns each application a unique Linux user ID (the ID is used only by the system and is unknown to the application). The system sets permissions for all the files in an application so that only the user ID assigned to that application can access them.
    • 默认情况下,系统给每个应用分配一个独立的Linux用户ID(这个ID只由系统使用并且对应用来说是不可知的),系统给在某个应用中的所有文件设置了权限,所以只有分配了那个用户ID的应用才能访问它们
    • Each process has its own virtual machine (VM),每个进行捅有它自己的虚拟机) so an application's code runs in isolation from other applications.所以一个应用代码的运行,与其他应用代码的运行是隔离的.
    • By default, every application runs in its own Linux process. Android starts the process when any of the application's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other applications.
    • 默认情况,每个应用运行在它自己的Linux进程中,当任意一个应用的组件需要被执行时,Android启动它的进程,当它不再需要时或系统为其他应用回收内存时关掉该进程

    In this way, the Android system implements the principle of least privilege. 通过这种方法,Android系统实现了最小特权原则

    That is, each application, by default, has access only to the components that it requires to do its work and no more. This creates a very secure environment in which an application cannot access parts of the system for which it is not given permission.

  • 默认,每个应用仅仅访问需要工作的组件,并不多做其他的事。这样创建了一个非常安全的环境,应用不能访问系统没有授权的其他部分

    However, there are ways for an application to share data with other applications and for an application to access system services:

  • 然而,应用可以有多种方法来与其他应用,共享数据及访问系统服务

    • It's possible to arrange for two applications to share the same Linux user ID, 有可能安排两个应用共用一个linux系统ID
    • in which case they are able to access each other's files. 在那种情况下,它们能互相访问相互的数据
    • To conserve system resources, applications with the same user ID can also arrange to run in the same Linux process and share the same VM (the applications must also be signed with the same certificate).
    • 为了节约系统资源,捅用相同用户ID的应用,可能也被安排运行在同一个Linux进程中并共享相同的VM(应用必须被签名成同样的认证)
    • An application can request permission to access device data such as the user's contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and more. All application permissions must be granted by the user at install time.
    • 所用应用能请求允许访问硬件数据,比如像用户通信录,SMS消息及可挂载的存储设备(SD card),摄像头,蓝牙等,所有应用的权限必须在用户安装时被许可

    That covers the basics regarding how an Android application exists within the system. 上述了一个应用怎样存在于一个系统中的相关基本概念,

    The rest of this document introduces you to:这个文档的其他部分将向你介绍

    • The core framework components that define your application.定义在你的应用中核心框架组件
    • The manifest file in which you declare components and required device features for your application.在manifest中,给你的应用,声明组件及设备特点请求
    • Resources that are separate from the application code and allow your application to gracefully optimize its behavior for a variety of device configurations.独立于应用代码的资源,可以让你的应用极大的优化它在各种配置设备的表现

     

     

     

     

     

    Application Components   应用组件

    Application components are the essential building blocks of an Android application. 应用组件是构建Android应块的关键。                                                                                  

  • Each component is a different point through which the system can enter your application.每个组件是一个不同的入点,系统可以从这些点进入到你的应用。                                  

  • Not all components are actual entry points for the user and some depend on each other, 对于用户来说,并不是每个组件都是实际的入点,但它们之间有一些依赖

  • but each one exists as its own entity and plays a specific role—each one is a unique building block that helps define your application's overall behavior.但是每一个存在的组件都有它自己的一个入点,并扮演一个特定的角色--每一个都是独一无二的构建块,帮助你定义你的应用的整体行为

  • There are four different types of application components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.有四个不同类型的应用组件,每个类型服务于一个不同的目的,并有不同的生命周期,生命周期定义了如何创建和销毁它.

    Here are the four types of application components:下面是四种应用组件

    Activities活动
    An activity represents a single screen with a user interface. 一个 activity在一个屏幕,显示一个用户接口
    For example, an email application might have one activity that shows a list of new emails, 比如,一个email应用可能有一个activity,这个activity用于显示新的email列表
    another activity to compose an email, and another activity for reading emails. 而另一个activity用于写邮件,还有一个activity用于读取邮件
    Although the activities work together to form a cohesive user experience in the email application, each one is independent of the others.
    虽然这些activities一起工作于email应用中,形成一个完整的用户体验但每一个部分又是相互独立的.
    As such, a different application can start any one of these activities (if the email application allows it).
    正因如此,不同的应才能启动这些活动的任意一个(如个email应用允许它)
    For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture.
    比如,一个照相的应用,能开启一个email应用中写封新邮件的活动,让用户分享一张照片

    An activity is implemented as a subclass of Activity and you can learn more about it in the Activities developer guide.一个activity被当作Activity的子类来实现的,在Activities开发指南中,你可以学到更多关于它的使用

     

    Services服务
    A serviceis a component that runs in the background to perform long-running operations or to perform work for remote processes. 一个service是长期运行在后台,执行操作的组件,甚至可以为远程进程工作
    A service does not provide a user interface. 一个服务不提供用户界面
    For example, a service might play music in the background while the user is in a different application, 比如,当用户在其他应用中时,一个服务可能在后台播放音乐
    or it might fetch data over the network without blocking user interaction with an activity. 或者在后台获取数据,这并不影响用户跟其他的活动进行交互操作
    Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it. 其他的组件,比如一个activity,可以启动一个服务,并可以让它运行或者邦定到这个activity,以便与其进行交互操作.

    A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide.一个服务是作为Service子类来实现的,在Services开发南中你能学到更多关于它的使用

     

    Content providers 内容提供者
    A content providermanages a shared set of application data. 一个content provider管理共享的应用数据集
    You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access.
    你可以把数据存在文件系统中,一个SQLite数据库中,网上,或你应用可以访问的永久存储器中
    Through the content provider, other applications can query or even modify the data (if the content provider allows it).
    通过内容提供者,其他的应用可以查询甚至修改数据(如果内容提供者允许的话)
    For example, the Android system provides a content provider that manages the user's contact information. 比如,Android系统提供一个内容提供者管理用户通信录信息
    As such, any application with the proper permissions can query part of the content provider (such as ContactsContract.Data) to read and write information about a particular person. 因此,任何捅用适当权限的应用,可以查询内容提供者的部分来(比如 ContactsContract.Data)读取和写入关于某个人的信息
    Content providers are also useful for reading and writing data that is private to your application and not shared. For example, the Note Pad sample application uses a content provider to save notes.内容提供者对于读取和写入属于你的应用的私有的非共享数据也是非常有用的,比如 Note Pad样例应用程序,就使用内容提供者来保存笔记的

    A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other applications to perform transactions.

    一个内容提供者被当作的子类实现,并且必须实现一套标准的APIs,以让其他的应用能执行交换操作。

    For more information, see the Content Providers developer guide.参考Content Providers开发指南,以了解更多信息.

     

    Broadcast receivers广播接收者
    A broadcast receiveris a component that responds to system-wide broadcast announcements.广播接收者是一个响应系统范围广播公告(通知)的组件
    Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured.
    许多广播信息,都是来源于系统,比如,通知屏幕关闭的公告,电量低,或抓取了一张图片.
    Applications can also initiate broadcasts—for example, to let other applications know that some data has been downloaded to the device and is available for them to use.
    应用也能发起广播,比如,让其他的应用知道一些数据已下载到设备了,并且他们可以使用了。
    Although broadcast receivers don't display a user interface, they may create a status bar notificationto alert the user when a broadcast event occurs.
    虽然广播接收者,不能显示用户界面,但当一个广播事件发生时,它们可以创建一个状态通知器,去提醒用户
    More commonly, though, a broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work.
    但更多情况下,一个广播接收者只是一个其他组件,想要做极小量事件的一个"gateway”(途径)
    For instance, it might initiate a service to perform some work based on the event举例,它可能发起一个服务,去执行关于某个事件的一些工作..

    A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object. For more information, see the BroadcastReceiver class.

    一个广播接收者,是当作BroadcastReceiver子类被实现的.每个广播接收者都是从Intent对象衍生出来的。更多信息,请参考BroadcastReceiver

    A unique aspect of the Android system design is that any application can start another application’s component.

  • 任何一个应用能启动另一个其他应用的组件,是Android系统设计独一无二的方面(aspect).

  • For example, if you want the user to capture a photo with the device camera, 比如,你想要用设备的照相机拍一张图片

  • there's probably another application that does that and your application can use it, instead of developing an activity to capture a photo yourself. 其他的应用已经有了这个功能,并且你的应用可以使用它,而不需要你自己去开发一个拍照相的activity.

  • You don't need to incorporate or even link to the code from the camera application. Instead, you can simply start the activity in the camera application that captures a photo.

  • 你并不需要合并(包含)或者甚至是链接camera应中的代码; 而只是,简单的启动camera应用中的活动,来拍照就可以了.

  • When complete, the photo is even returned to your application so you can use it. To the user, it seems as if the camera is actually a part of your application

  • 当拍照完成,甚至把照片返回给你的应用,所以你能使用它。对于用户来讲,camera像是你应用中一部分

  • When the system starts a component, it starts the process for that application (if it's not already running) and instantiates the classes needed for the component.

  • 当系统开启一个组件时,它会启动那个应用的进程(如果该应用没有运行),并实例化该组件所需要的类.

  • For example, if your application starts the activity in the camera application that captures a photo, that activity runs in the process that belongs to the camera application, not in your application's process.

  • 举例,如果你的应用开启一个camera应用的activity,来拍照,这个activity将运行在属于camera应用的进程中,而不是在你的应用的进程中

  • Therefore, unlike applications on most other systems, Android applications don't have a single entry point (there's no main() function, for example).

  • 因此,不像大多数其他的系统的应用,Android应用,没有单个的入点(比如没有main()函数)

    Because the system runs each application in a separate process with file permissions that restrict access to other applications, your application cannot directly activate a component from another application.

  • 因为系统运行的每个应用,在一个带有文件权限的,独立的进程中,这样限制了对其他应用的访问,你的应用不能直接访问其他应用中的组件

  • The Android system, however, can. So, to activate a component in another application, you must deliver a message to the system that specifies your intent to start a particular component. The system then activates the component for you.

  • 但时,Android系统也能激活其他应用的组件.你必须传一个消息给系统,指定你想要启动的组件,然后系统为你激活这个组件

     

    Activating Components激活组件

    Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent.

    4个组件中的其中三个组件---activities,serivces,和broadcast receivers----是被叫做intent的异步消息激活的.

    Intents bind individual components to each other at runtime (you can think of them as the messengers that request an action from other components), whether the component belongs to your application or another.在运行时,Intents把某个的组件与其他的组件互相邦定,而不管这个组件是否属于你的应用还是其他的应用(你可以把它们想像成一个消息,用于请求一个其他组件的动作)

    An intent is created with an Intent object, which defines a message to activate either a specific component or a specific type of component—an intent can be either explicit or implicit, respectively.一个intent是一个由Intent创建的对象.该对象定义了一个激活某个特定组件或者某个组件类型的消息,一个intent可以是显示的,同样,也可以是隐式的.

    For activities and services, an intent defines the action to perform (for example, to "view" or "send" something) and may specify the URI of the data to act on (among other things that the component being started might need to know).

    对于activities和services,一个intent(意图)定义了一个要执行的动作(比如:to”view”或"send" 些什么),并指定了要采用的URI格式的数据(其中一些,是其他组件启动所需要知道的)

    For example, an intent might convey a request for an activity to show an image or to open a web page.

    比如,一个intent可能传送一个请求给一个activity,要显示一张图片或打开一个网页

    In some cases, you can start an activity to receive a result, in which case, the activity also returns the result in an Intent (for example, you can issue an intent to let the user pick a personal contact and have it returned to you—the return intent includes a URI pointing to the chosen contact).

    在有些情况,你启动一个activity接收一个结果,这种情况下,activity将在Intent返回一个结果.(比如,你可以指示一个intent,让用户取一个人的联系方式,并返回给你,返回的intent中会包含一个指向选定联系方式的URI.)

    For broadcast receivers, the intent simply defines the announcement being broadcast (for example, a broadcast to indicate the device battery is low includes only a known action string that indicates "battery is low").对于广播接收者,intent只是定义了一个做为广播的公告.(比如,一个广播指出,设备电池低,它只是包含了一个动作字串,表示”电池低”)

    The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from a ContentResolver.

    其他组件,内容提供者,不会被intents所激活.进一步讲,它是内容解释者(ContentResolver)所请求的目标所激活的

    The content resolver handles all direct transactions with the content provider 内容解释者,处理所有与内容提供者的直接交换

    so that the component that's performing transactions with the provider doesn't need to and instead calls methods on the ContentResolver object. 所以组件不需要执行与提供者交换,而是调用ContentResolver对象方法.(这一句不好理解。)

    This leaves a layer of abstraction between the content provider and the component requesting information (for security).为了安全起见,组件请求信息与内容提供者之间有一个抽象层.

    There are separate methods for activiting each type of component:下面是激活各种类型组件的几个方法

    For more information about using intents, see the Intents and Intent Filters document.关于使用intents的详细信息,请看ntents and Intent Filters 文档

    More information about activating specific components is also provided in the following documents: Activities, Services, BroadcastReceiver and Content Providers.

    在后面的文档中,也有一些关于激活某个组件的信息Activities, Services, BroadcastReceiver and Content Providers.

     

    The Manifest File(清单文件)

    Before the Android system can start an application component, the system must know that the component exists by reading the application's AndroidManifest.xml file (the "manifest" file). 在Android系统开启一个应用组件之前,系统必须通过读取AndroidManifest.xml文件来知道组件的存在

    Your application must declare all its components in this file, which must be at the root of the application project directory.

    你的应用必须把它所有的组件声明在这个文件中,并且必须在应用工程的根目录下

    The manifest does a number of things in addition to declaring the application's components, such as:

    这个manifest文件除了声明组件外,还处理了许多其他的事情,比如

    • Identify any user permissions the application requires, such as Internet access or read-access to the user's contacts.
    • 指定应用请求的其他权限,访问网络或访问用户的通信录
    • Declare the minimum API Level required by the application, based on which APIs the application uses. 声明应用要求的最小API Level,应用使用的是那个API
    • Declare hardware and software features used or required by the application, such as a camera, bluetooth services, or a multitouch screen. 声明应用请求和使用的软硬件特征,比如照相机,蓝牙服务,或多点触模屏
    • API libraries the application needs to be linked against (other than the Android framework APIs), such as the Google Maps library. 应用需要链接的API库,比如Google Maps library
    • And more 等等
    Declaring components声明组件

    The primary task of the manifest is to inform the system about the application's components. For example, a manifest file can declare an activity as follows:

    manifest文件的主要任务是告诉系统,应用的组件,比如,一个manifest可以这样声明一个activity

    <?xml version="1.0" encoding="utf-8"?>
    <manifest ... >
        <application android:icon="@drawable/app_icon.png" ... >
            <activity android:name="com.example.project.ExampleActivity"
                      android:label="@string/example_label" ... >
            </activity>
            ...
        </application>
    </manifest>

    In the <application> element, the android:icon attribute points to resources for an icon that identifies the application.在<application> 元素中,android:icon指定应用的icon资源

    In the <activity> element, the android:name attribute specifies the fully qualified class name of the Activity subclass and the android:label attributes specifies a string to use as the user-visible label for the activity.

    <activity> 元素中的,android:name 属性,指定Activity子类的完全类名

    You must declare all application components this way:你必须这样声明 所有应用的组件

    • <activity>elements for activities 声明活动的元素
    • <service>elements for services 声明服务的元素
    • <receiver>elements for broadcast receivers 声明广播接收者元素
    • <provider> elements for content providers 声明内容提供者元素

    Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run.

    在你代码中包含的,Activites,services和内容提供者,若没有在manifest中声明,对系统来说是不可见的,即将永远不会运行

    However, broadcast receivers can be either declared in the manifest or created dynamically in code (as BroadcastReceiver objects) and registered with the system by calling registerReceiver().但是,广播接收者即可以在manifest中声明,也可以在代码中动态创建(做为BroadcastReceiver对象)并且通过registerReceiver()方法向系统注册

    For more about how to structure the manifest file for your application, see the The AndroidManifest.xml File documentation. 了解manifest文件的详细构建过程,请看The AndroidManifest.xml File文档

     

    Declaring component capabilities 声明组件功能

    As discussed above, in Activating Components, you can use an Intent to start activities, services, and broadcast receivers.

    就如在上面的Activating Components中所讨论的,你可以用一个Activating Components启动activities,services和broadcast 接收者.

    You can do so by explicitly naming the target component (using the component class name) in the intent. 你也可以在intent中显式的指定目标组件(使用组件类名)

    However, the real power of intents lies in the concept of intent actions. 然而,intent真正强大的是它的intent action.(动作)

    With intent actions, you simply describe the type of action you want to perform (and optionally, the data upon which you’d like to perform the action) and allow the system to find a component on the device that can perform the action and start it.

    通过使用intent动作,你只须简单的描述你要执行的action类型,(并且,可选的与执行动作有关的数据),并且允许系统在设备上找到一个组件,这样就可以执行那个动作并启动它

    If there are multiple components that can perform the action described by the intent, then the user selects which one to use.

    如果有多个组件可以执行,intent指定的action,那么用户选择执行那一个.

    The way the system identifies the components that can respond to an intent is by comparing the intent received to the intent filters provided in the manifest file of other applications on the device.

    通过比较设备上的其他应用的manifest文件上的intent filters与接收到的intent.系统确定那个组件可以响应一个intent.

    When you declare a component in your application's manifest, you can optionally include intent filters that declare the capabilities of the component so it can respond to intents from other applications. 当你在你的应用的manifest中声明一个组件时,你可以可选择包括intent filters(意图过滤器),来指定组件的功能,以让其能响应其他应用的intents.

    You can declare an intent filter for your component by adding an <intent-filter> element as a child of the component's declaration element.

    你可以加一个组件声明的元素的子元素<intent-filter>,为你组件声明一个意图过滤器,

    For example, an email application with an activity for composing a new email might declare an intent filter in its manifest entry to respond to "send" intents (in order to send email).

    比如,一个email应用中,新建emali的一个activity可能在它的manifest 中声明了一个意图过滤器,以便能响应”send”意图(为了发送邮件)

    An activity in your application can then create an intent with the “send” action (ACTION_SEND), which the system matches to the email application’s “send” activity and launches it when you invoke the intent with startActivity().然后,在你的应用中的一个activity,创建了一个带有”send” ACTION_SEND的意图,.当你调用startActivity()方法,启动该意图过滤器时,系统将其匹配到email应用的“send”活动,并运行它。

    For more about creating intent filters, see the Intents and Intent Filters document. 关于创建意图过滤器的详细信息,参考Intents and Intent Filters 文档

     
    Declaring application requirements声明应用请求

    There are a variety of devices powered by Android and not all of them provide the same features and capabilities. 有许多设备装了Android,但它们并不提供所有相同的特点和功能.

    In order to prevent your application from being installed on devices that lack features needed by your application, 为了避免你的应用,装在一个没有你应用所必特征的设备上.

    it's important that you clearly define a profile for the types of devices your application supports by declaring device and software requirements in your manifest file.

    通过在你的manifest文件中声明软件硬件要求,明了的指出你的应用支持的硬件类型是非常重要的

    Most of these declarations are informational only and the system does not read them, but external services such as Android Market do read them in order to provide filtering for users when they search for applications from their device.大多数声明仅仅只是信息,系统并不读取他们,但像Android市场这样的其他服务,将读取它们,以便让用户在为他们的设备寻找应用时,可以进行筛选.

    For example, if your application requires a camera and uses APIs introduced in Android 2.1 (API Level 7), you should declare these as requirements in your manifest file.

    比如,如果你的应用需要有照相机,并且使用的API是2.1(API Level 7),你应在你r的manifest文件中声明这些要求.

    That way, devices that do not have a camera and have an Android version lower than 2.1 cannot install your application from Android Market.

    这样,那些没有照相机并且Android版本低于2.1的设备,就不能从Android市场上安装你的应用.

    However, you can also declare that your applicaiton uses the camera, but does not require it. 但,你也可以声明你的应使用camera,但不必须要求

    In that case, your application must perform a check at runtime to determine if the device has a camera and disable any features that use the camera if one is not available.

    那种情况,你的应用必在运行时一个检查,以确定设备是否有一个照相机,如果没有照相机,并禁止与照相相关的功能。

    Here are some of the important device characteristics that you should consider as you design and develop your application: 下面是一些重要的设备特性,你在设计和开发应用时必须要考虑的..

    Screen size and density 屏幕尺寸与解释度
    In order to categorize devices by their screen type, Android defines two characteristics for each device: screen size (the physical dimensions of the screen) and screen density (the physical density of the pixels on the screen, or dpi—dots per inch). 为了能从它们的屏幕尺寸来分类设备,Android为每个设备定义了两个特性:屏幕尺寸(屏幕的物理尺寸)和解释度(在屏上的像素的物理密度,或者dpi--每英寸的点数)
     
    To simplify all the different types of screen configurations, the Android system generalizes them into select groups that make them easier to target.
    为了简化屏幕配置的所有不同类型,Android系统把它们分成可选的组,以便更容易定位 

    The screen sizes are: small, normal, large, and extra large.屏幕大小:小,正常,大和极大
    The screen densities are: low density, medium density, high density, and extra high density. 屏幕解释度:低解释度,中解释度,高解释度,和极高解释度

    By default, your application is compatible with all screen sizes and densities, because the Android system makes the appropriate adjustments to your UI layout and image resources. 黑认情况下,你的应用是兼容所有屏幕尺寸和解释度的,因为Android系统对此做了适当的调整,以使得它适合你的UI布局和图像资源

    However, you should create specialized layouts for certain screen sizes and provide specialized images for certain densities, using alternative layout resources, and by declaring in your manifest exactly which screen sizes your application supports with the <supports-screens> element.

    然而,你应为某个屏幕尺寸创建特殊的布局,并为某些解释度提供特定的图像,使用可选的资源,并在你的manifest文件中用<supports-screens> 元素声明,以明确指出你的应用支持的屏幕尺寸.

     

    For more information, see the Supporting Multiple Screens document. 更多信息,参考Supporting Multiple Screens文档

     

    Input configurations 输入配置
    Many devices provide a different type of user input mechanism, such as a hardware keyboard, a trackball, or a five-way navigation pad. 许多设备为用提供了一个不同类型输入装置,比如,硬件键盘,轨迹球,five-way导航pad.
    If your application requires a particular kind of input hardware, then you should declare it in your manifest with the <uses-configuration> element.如果你的应用必须要一个特别的输入硬件,那么你应在你的应用中使用 <uses-configuration>元素声明However, it is rare that an application should require a certain input configuration. 但时,应用必须要一个特别的输入配置的情况是极少的.
    Device features 设备特性
    There are many hardware and software features that may or may not exist on a given Android-powered device, such as a camera, a light sensor, bluetooth, a certain version of OpenGL, or the fidelity of the touchscreen. 在一个装有Android的设备中,有许多软硬件特性,有可能有,或有可能没有。比如照相机,光敏器件,蓝牙,或某个版本的OpenGL,或者触模屏的精度.
    You should never assume that a certain feature is available on all Android-powered devices (other than the availability of the standard Android library), so you should declare any features used by your application with the <uses-feature>element.
    你应该从不假设,在所有的装有Android的设备中某个特点是可用的(除了标准的Android库),所以你应该用 <uses-feature>元素声明你的应用支持的特征.
    Platform Version 平台版本
    Different Android-powered devices often run different versions of the Android platform, such as Android 1.6 or Android 2.3.
    不同的Android设备,经常运行不同的Android平台版本,比如Android1.6或者2.3.
    Each successive version often includes additional APIs not available in the previous version. 每一个成功的版本通常包括在前一个版本中不可用的API。
    In order to indicate which set of APIs are available, each platform version specifies an API Level(for example, Android 1.0 is API Level 1 and Android 2.3 is API Level 9).
    为了指出,那些APIs集是可用的,每个平台版本指定了一个 API Level(比如, Android 1.0 is API Level 1 and Android 2.3 is API Level 9)
    If you use any APIs that were added to the platform after version 1.0, you should declare the minimum API Level in which those APIs were introduced using the <uses-sdk> element. 如果你使用的APIs是在1.0版之后,加入到平台的,你应该用 <uses-sdk>元素,声明最小API级别,这样就指出了那些API将被采用.
    It's important that you declare all such requirements for your application, 为你的应用声明所有必要性的要求非常重要
    because, when you distribute your application on Android Market, 因为,当你把你的应用发布到Android市场
    Market uses these declarations to filter which applications are available on each device. 市场,将用这些声明信息来过滤出,那些应用在每个设备是可用的
    As such, your application should be available only to devices that meet all your application requirements. 同样,你的应用应该只能在满足所有你应用需求的设备上才可用
  • For more information about how Android Market filters applications based on these (and other) requirements, see the Market Filters document.

  • 更多关于Android市场如何基于这些需求过滤的,请看Market Filters文档

    Application Resources应用资源

    An Android application is composed of more than just code—it requires resources that are separate from the source code, such as images, audio files, and anything relating to the visual presentation of the application. 一个Android应用的组成不仅只是代码----它还有与代码独立的资源,比如图像,音频文件,及与应用可显图像任何其他相关的(东东)

  • For example, you should define animations, menus, styles, colors, and the layout of activity user interfaces with XML files.

  • 比如,你应该定义动画,菜单,风格,颜色,和用XML文件定义活动的布局

  • Using application resources makes it easy to update various characteristics of your application without modifying code and—by providing sets of alternative resources—enables you to optimize your application for a variety of device configurations (such as different languages and screen sizes). 使用应用资源,能让你的应用在不修改任何代码的情况下容易的升级各种特性---并且通过提供一套可选取的资源--能优化你的应用在各种配置不同的设备中的表现(比如不同的语言和屏幕尺寸)

  • For every resource that you include in your Android project, the SDK build tools define a unique integer ID, which you can use to reference the resource from your application code or from other resources defined in XML.

  • 对于每个包含在你的Android工程中的资源,SDK将其定义成一个唯一的整型ID,这样你就可以在你的代码中或在XML文件中定义的其他资源中引用它For example,

  • if your application contains an image file named logo.png (saved in the res/drawable/ directory), the SDK tools generate a resource ID named R.drawable.logo, which you can use to reference the image and insert it in your user interface. 如果你的应用包括一个图片名字是logo.png(保存在res/drawable/directory),SDK工具将生成一个资源ID命名成R.drawable.logo,你可以用它来引用图片,并插入你的用户界面中

  • One of the most important aspects of providing resources separate from your source code is the ability for you to provide alternative resources for different device configurations. 提供与你的代码分开的资源的一个很重要的方面是,使得你能为不同的配置的设备提供可选资源.

  • For example, by defining UI strings in XML, you can translate the strings into other languages and save those strings in separate files.

  • 比如,在XML中定义UI字串,你可以把字串翻译成各种不同的语言并保存在不同的文件中

  • Then, based on a language qualifier that you append to the resource directory's name (such as res/values-fr/ for French string values) and the user's language setting, the Android system applies the appropriate language strings to your UI. 然后,以基于语言限定词,你可以追加资源目录名(比如res/values-fr/ 用语法语资源),和用户语言设置,Android系会将相应的资源应用到你的UI中.

    Android supports many different qualifiers for your alternative resources. Android为你的可选资源,支持许多不同的qualifiers (限定词)

  • The qualifier is a short string that you include in the name of your resource directories in order to define the device configuration for which those resources should be used.

  • 限定词是一个包括在你的目录名中的一个简短的字串,是为了定义那些资源将用在,该配置的设备上.

  • As another example, you should often create different layouts for your activities, depending on the device's screen orientation and size. 再如,由于设备的屏幕的方向和尺寸不同,你通常需要为你的活动定义不同的布局.

  • For example, when the device screen is in portrait orientation (tall), you might want a layout with buttons to be vertical, but when the screen is in landscape orientation (wide), the buttons should be aligned horizontally. 比如,若设备的屏幕是竖向(高),你可能要一个带有重直button 的布局,当屏幕是横向的(宽),按钮应是水平对齐的

  • To change the layout depending on the orientation, you can define two different layouts and apply the appropriate qualifier to each layout's directory name.

  • 要根据方向来改变布局,你要定义两个不同的布局,并在布局的目录名中使用相应的限定词(qualifier)

  • Then, the system automatically applies the appropriate layout depending on the current device orientation. 然后,系统将自动根据当前的设备朝向来应用相应的布局

    For more about the different kinds of resources you can include in your application and how to create alternative resources for various device configurations, see the Application Resources developer guide. 要详细了解,你的应用中能包含的各种资源,及如何为各种配置的设备创建可选资源,请看Application Resources开发指南

    <终于翻译完了,花了一天多的时间>

     

     

     

你可能感兴趣的:(application)