`
su1216
  • 浏览: 671988 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
Group-logo
深入入门正则表达式(jav...
浏览量:72009
E60283d7-4822-3dfb-9de4-f2377e30189c
android手机的安全问...
浏览量:128920
社区版块
存档分类
最新评论

android Intents和Intent Filters - 开发文档翻译 - 1

阅读更多

由于本人英文能力实在有限,不足之初敬请谅解

本博客只要没有注明“转”,那么均为原创,转贴请注明本博客链接链接

 

android 进程与线程 - 开发文档翻译 - 进程

android 进程与线程 - 开发文档翻译 - 线程

 

其他系列的翻译

android activity开发文档翻译 - 1 - 基础篇

android activity开发文档翻译 - 2 - 生命周期篇

 

android task与back stack 开发文档翻译 - 1

android task与back stack 开发文档翻译 - 2

android task与back stack 开发文档翻译 - 3

 

android Fragment开发文档翻译 - 1

android Fragment开发文档翻译 - 2

 

本系列并没有对原文100%翻译,也没有100%的贴出原文

 

 

Intents and Intent Filters

Intents和Intent Filters

Three of the core components of an application — activities, services, and broadcast receivers — are activated through messages, called intents. 

Intent messaging is a facility for late run-time binding between components in the same or different applications. 

The intent itself, an Intent object, is a passive data structure holding an abstract description of an operation to be performed — or, often in the case of broadcasts, a description of something that has happened and is being announced. 

There are separate mechanisms for delivering intents to each type of component:

应用的3大核心组件 - activity,service和broadcast receiver - 通过信息激活,被称之为intent。

Intent消息是运行时后期在相同或不同应用中绑定组件的便捷工具。

intent本身,一个Intent对象,是一个持有要执行操作的抽象描述(或者,经常在broadcast情况中,已经发生并且正在宣布的事情的一个描述)的可传递的数据结构

分发intent到每个类型组件有一些独立的机制。

 

 

An Intent object is passed to Context.startActivity() or Activity.startActivityForResult() to launch an activity or get an existing activity to do something new. (It can also be passed to Activity.setResult() to return information to the activity that called startActivityForResult().)

一个Intent对象传到Context.startActivity()或者Activity.startActivityForResult()来启动一个activity或者获得一个已经存在的activity来做一些新的事情(也可以是传到Activity.setResult()来返回信息给调用startActivityForResult()的activity)

 

 

An Intent object is passed to Context.startService() to initiate a service or deliver new instructions to an ongoing service. 

Similarly, an intent can be passed to Context.bindService() to establish a connection between the calling component and a target service. 

It can optionally initiate the service if it's not already running.

一个Intent对象传到Context.startService()来初始化一个service或者给一个运行的service发布新的指令

简单的说,一个intent可以传递给Context.bindService()来建立一个调用者组件和目标service之间的连接。

如果它尚未运行,它可以选择启动服务。

 

 

Intent objects passed to any of the broadcast methods (such as Context.sendBroadcast(), Context.sendOrderedBroadcast(), or Context.sendStickyBroadcast()) are delivered to all interested broadcast receivers. 

Many kinds of broadcasts originate in system code.

Intent对象传递到任何广播方法中(比如Context.sendBroadcast(), Context.sendOrderedBroadcast()或者Context.sendStickyBroadcast())向所有感兴趣的broadcast receiver发布。

很多各种各样的广播在系统代码中产生。

 

 

In each case, the Android system finds the appropriate activity, service, or set of broadcast receivers to respond to the intent, instantiating them if necessary. 

There is no overlap within these messaging systems: Broadcast intents are delivered only to broadcast receivers, never to activities or services. 

An intent passed to startActivity() is delivered only to an activity, never to a service or broadcast receiver, and so on.

每一个案例中,Android系统找到适合的activity,service或者broadcast receiver集合来响应intent,如果有必要的话实例化他们。

这些信息系统内没有重叠部分:广播intent仅会被发送到broadcast receiver,不会发送到activity和service

传递给startActivity()之后发送到一个activity中,不会发到service或者broadcast receiver……

 

 

This document begins with a description of Intent objects. 

It then describes the rules Android uses to map intents to components — how it resolves which component should receive an intent message. 

For intents that don't explicitly name a target component, this process involves testing the Intent object against intent filters associated with potential targets.

这篇文档以Intent对象描述为开始

然后描述Android用来映射intent到组件的规则 - 它如何分辨哪一个组件应该收到一个intent消息

对于隐式的intent来说,这个过程相对于intent过滤器包含关联潜在的目标测试intent对象。

 

 

Intent Objects

Intent对象

An Intent object is a bundle of information. 

It contains information of interest to the component that receives the intent (such as the action to be taken and the data to act on) plus information of interest to the Android system (such as the category of component that should handle the intent and instructions on how to launch a target activity). 

Principally, it can contain the following:

一个Intent对象是一捆信息

它包含收到intent的组件感兴趣的信息(比如要采取的行为和遵循的数据)加上感兴趣的Android系统信息(比如应该处理intent和指令如何启动一个目标activity的组件的种类)

 

 

Component name

组件名称

The name of the component that should handle the intent. 

This field is a ComponentName object — a combination of the fully qualified class name of the target component (for example "com.example.project.app.FreneticActivity") and the package name set in the manifest file of the application where the component resides (for example, "com.example.project"). 

The package part of the component name and the package name set in the manifest do not necessarily have to match.

The component name is optional. 

If it is set, the Intent object is delivered to an instance of the designated class. 

If it is not set, Android uses other information in the Intent object to locate a suitable target — see Intent Resolution, later in this document.

The component name is set by setComponent(), setClass(), or setClassName() and read by getComponent().

应该处理intent组件的名称

这个字段是ComponentName对象 - 目标组件的全限定类名(例如:"com.example.project.app.FreneticActivity")和在manifest文件中设置的应用包名(组件驻留的地方)的一个组合(例如"com.example.project")

组件名称的包部分和在manifest中设置的包名不需要匹配。

组件名称是可选的

如果设置了,Intent对象被发送到指定类的一个实例。

如果没有设置,Android使用其他在Intent对象中的信息类定位一个合适的目标 - 参看Intent解析,此文档的后面。

组件名称通过setComponent(), setClass(),或setClassName()设置,在getComponent()读取。

 

 

Action

行为

A string naming the action to be performed — or, in the case of broadcast intents, the action that took place and is being reported. 

The Intent class defines a number of action constants, including these:

一个字符串命名的行为被执行 - 或者在broadcast intent事例中,发生过的并且正被报告的行为

Intent类定义了一些行为常量,包括:

 

Constant Target component Action
ACTION_CALL activity Initiate a phone call.
ACTION_EDIT activity Display data for the user to edit.
ACTION_MAIN activity Start up as the initial activity of a task, with no data input and no returned output.
ACTION_SYNC activity Synchronize data on a server with data on the mobile device.
ACTION_BATTERY_LOW broadcast receiver A warning that the battery is low.
ACTION_HEADSET_PLUG broadcast receiver A headset has been plugged into the device, or unplugged from it.
ACTION_SCREEN_ON broadcast receiver The screen has been turned on.
ACTION_TIMEZONE_CHANGED broadcast receiver The setting for the time zone has changed.

See the Intent class description for a list of pre-defined constants for generic actions. 

Other actions are defined elsewhere in the Android API. 

You can also define your own action strings for activating the components in your application. 

Those you invent should include the application package as a prefix — for example: "com.example.project.SHOW_COLOR".

参看Intent类中为基本行为预定义常量的描述

其他行为在Android API其他地方定义

你也可以为激活你应用中的组件定义你自己的行为字符串

那些你创造的应该包含应用的包名作为前缀 - 例如:"com.example.project.SHOW_COLOR"

 

 

The action largely determines how the rest of the intent is structured — particularly the data and extras fields — much as a method name determines a set of arguments and a return value. 

For this reason, it's a good idea to use action names that are as specific as possible, and to couple them tightly to the other fields of the intent. 

In other words, instead of defining an action in isolation, define an entire protocol for the Intent objects your components can handle.

action主要决定了intent其余部分是如何构造的 - 尤其是数据和附加域部分 - 这很像一个方法名决定一组实参和一个返回值

由于这个原因,使用action并尽量指定其name是一个好的办法,为了紧密的把他们连接到intent其他域中。

换句话说,为你组件要处理的Intent定义一个完整的协议而不是单独的定义一个action

 

 

The action in an Intent object is set by the setAction() method and read by getAction().

Intent对象中的action通过setAction()设置,getAction()读取

 

 

Data

数据

The URI of the data to be acted on and the MIME type of that data. 

Different actions are paired with different kinds of data specifications. 

For example, if the action field is ACTION_EDIT, the data field would contain the URI of the document to be displayed for editing. 

If the action is ACTION_CALL, the data field would be a tel: URI with the number to call. 

Similarly, if the action is ACTION_VIEW and the data field is an http: URI, the receiving activity would be called upon to download and display whatever data the URI refers to.

遵循的数据中的URI和此数据中的MIME类型

不同的action与不同类型的数据规格配对。

例如:如果action为ACTION_EDITdata会包含要显示编辑的文档的URI

如果action为ACTION_CALL,data会包含一个电话号码:带有要拨打的号码的URI

相似的,如果action为ACTION_VIEW并且data域为一个http:URI,接收它的activity不论data中URI指向的地址,都会下载并且显示。

 

 

When matching an intent to a component that is capable of handling the data, it's often important to know the type of data (its MIME type) in addition to its URI. 

For example, a component able to display image data should not be called upon to play an audio file.

In many cases, the data type can be inferred from the URI — particularly content: URIs, which indicate that the data is located on the device and controlled by a content provider (see the separate discussion on content providers). 

But the type can also be explicitly set in the Intent object. 

The setData() method specifies data only as a URI, setType() specifies it only as a MIME type, and setDataAndType() specifies it as both a URI and a MIME type. 

The URI is read by getData() and the type by getType().

当一个intent与一个有能力处理data的组件匹配时,除了它的URI之外,了解data的类型(MIME类型)总是很重要的。

例如:一个能够显示图片数据组件不应该用来播放音频文件。

很多例子中,data类型可以从URI推测出 - 特别是content:URI,指出data在设备上的位置并且由content provider控制(参看content provider独立的讨论)。

但是类型也可以显式的设置在Intent对象中。

setData()方法指定data只作为URI,setType()指定其只作为一个MIME类型,setDataAndType()同时指定其为URI和MIME类型。

通过getData()读取URI,getType()获取类型

 

 

Category

类别

A string containing additional information about the kind of component that should handle the intent. 

Any number of category descriptions can be placed in an Intent object. 

As it does for actions, the Intent class defines several category constants, including these:

一个字符串包含应该处理intent的这类组件的附加信息。

任何数量的Category描述可以放置到一个Intent对象中。

就像为action做的一样,Intent类定义几种常量,包括:

 

Constant Meaning
CATEGORY_BROWSABLE The target activity can be safely invoked by the browser to display data referenced by a link — for example, an image or an e-mail message.
CATEGORY_GADGET The activity can be embedded inside of another activity that hosts gadgets.
CATEGORY_HOME The activity displays the home screen, the first screen the user sees when the device is turned on or when the Home button is pressed.
CATEGORY_LAUNCHER The activity can be the initial activity of a task and is listed in the top-level application launcher.
CATEGORY_PREFERENCE The target activity is a preference panel.

See the Intent class description for the full list of categories.

The addCategory() method places a category in an Intent object, removeCategory() deletes a category previously added, and getCategories() gets the set of all categories currently in the object.

参见Intent类描述关于Category的完整列表

addCategory()方法放置一个category到Intent对象,removeCategory()删除一个之前添加的category,getCategories()获得当前对象中所有category的集合

 

 

Extras

附加数据

Key-value pairs for additional information that should be delivered to the component handling the intent. 

Just as some actions are paired with particular kinds of data URIs, some are paired with particular extras. 

For example, an ACTION_TIMEZONE_CHANGED intent has a "time-zone" extra that identifies the new time zone, and ACTION_HEADSET_PLUG has a "state" extra indicating whether the headset is now plugged in or unplugged, as well as a "name" extra for the type of headset. 

If you were to invent a SHOW_COLOR action, the color value would be set in an extra key-value pair.

The Intent object has a series of put...() methods for inserting various types of extra data and a similar set of get...() methods for reading the data. 

These methods parallel those for Bundle objects. 

In fact, the extras can be installed and read as a Bundle using the putExtras() and getExtras() methods.

应该发送到处理intent的组件中的附加数据键值对

就像一些action与指定的数据

例如:一个ACTION_TIMEZONE_CHANGED intent有一个识别新时区的"time-zone"附加数据,ACTION_HEADSET_PLUG有一个"state"附加数据指示现在耳机有没有插入,和一个耳机状态类型的“name”附加数据一样。

如果你想要创建一个SHOW_COLOR行为,颜色值应该设置在附加的键值对中。

Intent对象有一系列的put...()方法来插入各种类型的附加数据和相似的与get...()对应的set方法来读取数据

这些方法与Bundle对象方法平行

事实上,附加数据可以作为一个Bundle使用putExtras()和getExtras()方法安装和读取。

 

 

Flags

标志

Flags of various sorts. 

Many instruct the Android system how to launch an activity (for example, which task the activity should belong to) and how to treat it after it's launched (for example, whether it belongs in the list of recent activities). 

All these flags are defined in the Intent class.

各种flag

很多flag指示Android系统如何启动一个activity(例如:activity应该属于哪一个task)和在它启动之后如何看待它(比如:它是否属于最近activity列表中)

所有这些flag都定义在Intent类中。

 

 

The Android system and the applications that come with the platform employ Intent objects both to send out system-originated broadcasts and to activate system-defined components. 

To see how to structure an intent to activate a system component, consult the list of intents in the reference.

Android系统和与平台一起的应用使用Intent对象发出系统创建的广播并且激活系统定义的组件。

如何构造一个intent来激活一个系统组件参考intent说明列表。

 

 

 

Intents List: Invoking Google Applications on Android Devices

Intent列表:在Android设备上执行Google应用

The table below lists the intents that your application can send, to invoke Google applications on Android devices in certain ways. 

For each action/uri pair, the table describes how the receiving Google application handles the intent.

你的应用可以发送下面表格中intent一某中方式来执行Android设备上Google应用。

对于每一个action/uri对,表格描述了接收的Google应用如何处理intent

 

Note that this list is not comprehensive.

注意:这个列表并不完整。

(表格似乎显式有些问题,原表格地址:http://developer.android.com/guide/appendix/g-app-intents.html)

 

Target Application Intent URI Intent Action Result
Browser http://web_address
https://web_address
VIEW Open a browser window to the URL specified.
"" (empty string) 
http://web_address
https://web_address
WEB_SEARCH Opens the file at the location on the device in the browser.
Dialer tel: phone_number CALL

Calls the entered phone number. Valid telephone numbers as defined in the IETF RFC 3966 are accepted. Valid examples include the following:

  • tel:2125551212
  • tel: (212) 555 1212

The dialer is good at normalizing some kinds of schemes: for example telephone numbers, so the schema described isn't strictly required in the Uri(URI string)factory. However, if you have not tried a schema or are unsure whether it can be handled, use theUri.fromParts(scheme, ssp, fragment) factory instead.

Note:   This requires your application to request the following permission in your manifest: <uses-permission id="android.permission.CALL_PHONE" />

tel:phone_number
voicemail:

DIAL

Dials (but does not actually initiate the call) the number given (or the stored voicemail on the phone). Telephone number normalization described for CALL applies to DIAL as well.

Google Maps geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city
VIEW Opens the Maps application to the given location or query. The Geo URI scheme (not fully supported) is currently under development.

The z field specifies the zoom level. A zoom level of 1 shows the whole Earth, centered at the given lat,lng. A zoom level of 2 shows a quarter of the Earth, and so on. The highest zoom level is 23. A larger zoom level will be clamped to 23.

Google Streetview google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom VIEW Opens the Street View application to the given location. The URI scheme is based on the syntax used for Street View panorama information in Google Maps URLs.

The cbll field is required. The cbp and mz fields are optional.

 

lat latitude
lng longitude
yaw Panorama center-of-view in degrees clockwise from North.
Note: The two commas after the yaw parameter are required. They are present for backwards-compatibility reasons.
pitch Panorama center-of-view in degrees from -90 (look straight up) to 90 (look straight down.)
zoom Panorama zoom. 1.0 = normal zoom, 2.0 = zoomed in 2x, 3.0 = zoomed in 4x, and so on.
A zoom of 1.0 is 90 degree horizontal FOV for a nominal landscape mode 4 x 3 aspect ratio display Android phones in portrait mode will adjust the zoom so that the vertical FOV is approximately the same as the landscape vertical FOV. This means that the horizontal FOV of an Android phone in portrait mode is much narrower than in landscape mode. This is done to minimize the fisheye lens effect that would be present if a 90 degree horizontal FOV was used in portrait mode.
mapZoom The map zoom of the map location associated with this panorama. This value is passed on to the Maps activity when the Street View "Go to Maps" menu item is chosen. It corresponds to the zparameter in the geo: intent.

 

原文地址如下,英文水平实在有限,希望拍砖同时能给予指正。

http://developer.android.com/guide/components/intents-filters.html

http://developer.android.com/guide/appendix/g-app-intents.html

 

 

 

转贴请保留以下链接

本人blog地址

http://su1216.iteye.com/

http://blog.csdn.net/su1216/

2
4
分享到:
评论

相关推荐

    Android Intents and Intent Filters(一)

    Android Intents and Intent Filters(一) 对应博客地址:http://blog.csdn.net/michael__li/article/details/6947545

    Android Intents and Intent Filters(二)源代码

    Android Intents and Intent Filters(二)源代码 对应博客 http://blog.csdn.net/michael__li/article/details/6950127

    Intents and Intent Filters 理论中英双文

    内含四个pdf文件,分别为 Intent and Intent-filter Intents and Intent Filters理论英文 Intents and Intent Filters理论中文 Intent入门指南 详尽介绍关于android intent

    Android开发之旅 Intents和Intent Filters(实例部分)(免费)

    ### Android开发之旅:深入理解Intents与Intent Filters 在Android开发中,`Intents`与`Intent Filters`是实现组件间通信的关键技术。通过这两项技术,开发者可以让应用程序中的不同组件,甚至不同的应用程序之间...

    Android系列教程之十二:Intents and Intent Filters(三).docx

    总之,Intent和Intent Filters是Android系统的核心组成部分,它们使得不同应用间的交互变得简单而灵活。通过正确配置Intent Filter,开发者可以让自己的应用能够响应特定的Intent,从而实现各种功能,如拨打电话、...

    Android-Intents-3

    通过配置Intent Filters和发送Intents,可以灵活地控制哪些Activity可以在Tab之间切换,并且通过自定义图标增强了用户体验。这种做法不仅适用于简单的应用,也可以扩展到更复杂的应用场景中。希望本章节的内容对您的...

    Learning Android Intents

    在深入学习Android Intents之前,我们先来了解下什么是Intents以及它在Android开发中的重要性。Intents是Android平台中用于应用程序间通信的核心机制之一。通过Intents,不同的组件可以互相发送消息、启动活动或服务...

    Android-Intents-1

    从显式 Intents 到隐式 Intents,再到 Intent Filters 的定义,我们逐步掌握了如何在 Android 应用程序中有效地进行 Activity 之间的跳转和数据传输。同时,也了解了如何通过 URI 启动 Activity 以及如何在 Tabbed ...

    Android开发之旅

    Android开发之旅:环境搭建及HelloWorld 1 Android开发之旅:HelloWorld项目的目录结构 2 Android开发之旅:android架构 3 Android开发之旅:应用程序...Android开发之旅 Intents和Intent Filters(实例部分) 17

    Intents 和Intent filter 理论介绍

    Intent 在 Android 开发中扮演着至关重要的角色,它是应用程序组件间通信的关键机制,使得组件之间可以实现松散耦合的交互。Intent 不仅仅用于启动另一个 Activity,还可以启动 Service 或触发 Broadcast Receiver。...

    Android-Intents-2.

    在 Android 开发中,`Intents` 是一个非常重要的概念。它允许开发者定义应用程序内部以及不同应用程序之间的通信方式。在前一部分中,我们探讨了如何通过类名来调用 Activity,这种方式适用于明确知道目标 Activity ...

    Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面.

    在 Android 开发中,Intent 是一个非常重要的概念,它允许不同的应用程序之间进行交互和通信。在本文中,我们将探讨如何使用 Intent 跳转到系统应用中的拨号界面、联系人界面、短信界面等。 拨号界面 要跳转到拨号...

    Android开发指南中文版-----应用程序框架

    #### 十三、意图和意图过滤器(Intents and Intent Filters) 意图(Intent)用于在组件之间传递消息和数据,而意图过滤器(Intent Filters)则用于定义组件对哪些类型的Intent感兴趣。 #### 十四、数据存储(Data Storage...

    Android开发入门与实战+和第二版部分章节+第二版源代码

    本书主要内容为:Android开发环境搭建、Android SDK介绍、Android应用程序结构剖析,并对Android 中最重要的组件Activity、Intents&Intent Filters&Broadcast receivers、Intent、Service、Content Providers进行了...

    android 开发文档--经典珍藏

    ### Android开发文档--经典珍藏知识点汇总 #### 一、Android概述 **1.1 什么是Android** Android是一种基于Linux内核的操作系统,主要用于移动设备如智能手机和平板电脑。它由谷歌公司领导的开放手机联盟(Open ...

    Android-1_0-CC

    《Android-1_0-CC:安卓开发教学》是一份由Mark L. Murphy撰写的详尽的Android开发指南,这份资料对于希望深入了解Android应用程序设计与实现的开发者来说,具有极高的价值。以下是从该文件中提炼出的关键知识点,...

    Android Studio 实验二:Intent的使用

    Intent分为两种类型:显式Intent和隐式Intent。显式Intent用于启动特定的组件,如指定类名的Activity;而隐式Intent则是为了执行一个特定的动作,不指定具体的目标组件,而是通过Action、Data、Category等元数据来...

    Android代码-提升 Intent 体验的一个库

    Fluent API for common Intent use-cases in Android. This library wraps Intents with a clean and simple to understand interface for a number of specific use-cases. Sample usage See the sample project in...

Global site tag (gtag.js) - Google Analytics