安卓:了解意向过滤器 [英] Android: Understanding Intent-Filters

查看:147
本文介绍了安卓:了解意向过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Intent过滤,从而使某些环节会触发我的应用程序的开始(见本计算器线程,例如:<一href="http://stackoverflow.com/questions/2430045/how-to-register-some-url-namespace-myapp-app-start-for-accessing-your-progra/2430468#2430468">How注册某些URL命名空间(的myapp://app.start/)?通过在Android操作系统调用浏览器的URL访问你的程序)

I would like to create an Intent-Filter, so that certain links will trigger the start of my application (see this stackoverflow-thread for example: How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS? )

而努力,我想通了,我不很​​了解意图和意图过滤器(在manifest.xml定义)的实际工作。以下之间的区别是什么:

While trying, I figured out, that I dont quite understand how Intents and Intent-Filters (defined in the Manifest.xml) actually work. What is the difference between the following:

<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />

或以下内容:

or the following:

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MAIN" />

和什么是实际的类别和动作意向过滤器之间的差异。我读这页<一个href="http://developer.android.com/reference/android/content/Intent.html">http://developer.android.com/reference/android/content/Intent.html但我仍然缺少一个基本的了解。

And what is actually the difference between category and action Intent-Filters. I read this page http://developer.android.com/reference/android/content/Intent.html but I still missing a basic understanding.

推荐答案

而不是看着它从看你的应用程序的角度,翻转四周,看看它从意向方。

Instead of looking at it from your app's point of view, flip it around and look at it from the Intent side.

当创建一个Intent,创作者不知道是什么应用程序是系统处理的意图。但创作者不知道它想要做的(例如,一个应用程序可能需要让用户挑选出从什么地方该设备上的联系人)的东西,需要接触到其他应用程序在系统上,要求什么期望。

When an Intent is created, the creator has no idea what apps are on the system to handle that Intent. But the creator does know what it wants to do (e.g., an app might want to let the user pick out a contact from somewhere on the device), and needs to reach out to other apps on the system to ask for what's desired.

要做到这一点,意图有几件连接到他们的信息。其中包括行为和类别。

To do this, Intents have several pieces of information attached to them. Among them are actions and categories.

的行动在一般的方式定义意图想要做的,就像查看联系人,从画廊选择一个图像,动作等。

The actions define in a general way the action the Intent wants to do, like VIEW a contact, PICK an image from the Gallery, etc.

类别是一个额外的一条信息,使该意图的另一种方式来区分自己。例如,在浏览器中点击一个链接时,所创建的意图已经连接到它的可浏览的类别。

The category is an additional piece of information that gives the Intent another way to differentiate itself. For example, when a link in the browser is clicked, the Intent that is created has the BROWSABLE category attached to it.

所以,当操作系统解析的意图,这将寻找有意向的过滤器,包括所有条信息登记活动或BroadcastReceivers。如果打算指定PICK动作,没有意图过滤器与PICK行动活动将由考生处理这个意图的名单丢弃。

So, when the OS resolves the Intent, it will look for registered Activities or BroadcastReceivers that have an intent filter that includes all of pieces of information. If the Intent specifies the PICK action, Activities that do not have an intent-filter with the PICK action will be discarded from the list of candidates to handle the Intent.

在这种方式,动作类别,类型,以及与相关联的意图(可能)方案的组合组用于查明组活动的,可以处理的意图。当您在清单中设置你的意图过滤器,你告诉它意图的类,你可以处理的操作系统。

In this way, the combined set of action, categories, type, and (possibly) scheme associated with an Intent serve to pinpoint the set of Activities that can handle the Intent. When you set up your intent-filter in your manifest, you are telling the OS which class of Intents you can handle.

这篇关于安卓:了解意向过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆