Manifest intent filter翻译

http://developer.android.com/guide/topics/manifest/manifest-intro.html
 
 
 
It's okay to create a filter that includes more than one instance of  <action><data>, or 
可以创造一个包含多个的<action><data><category>的filter
 
<category>. If you do, you simply need to be certain that the component can handle any and all 
如果你这样做了,你需要确认这个组件能处理任何和全部的filter元的组合。
 
combinations of those filter elements.
 

Restricting access to components

限制访问组件

 
Using an intent filter is not a secure way to prevent other apps from starting your components. 
使用intent filter不是阻止其他应用运行你的组件的安全方法。
 
Although intent filters restrict a component to respond to only certain kinds of implicit intents, another 
虽然intent filter限制组件只对于特定隐式意图回应,
 
app can potentially start your app component by using an explicit intent if the developer determines 
其他的应用可能通过开发者直接用你的组件的名字发送一个显式的意图来开始运行你的组件。
 
your component names. If it's important that  only your own app is able to start one of your 
如果只有你自己的应用可以来运行你的组件十分重要。
 
components, set the  exported attribute to  "false" for that component.
为那个组件设置exported属性为false。
 
 
When the system receives an implicit intent to start an activity, it searches for the best activity for the
当系统接收到一个隐式的意图去开始一个activity,它会通过比较intent和intent filter的下面三个方面寻找
 
intent by comparing the intent to intent filters based on three aspects:
最适合的activity
 
  • The intent action
  • The intent data (both URI and data type)
  • The intent category
The following sections describe how an intents are matched to the appropriate component(s) in terms
下面的单元描述一个intent根据manifest文件声明的intent filter
 of how the intent filter is declared in an app's manifest file.
如何与合适的组件匹配
 
To specify accepted intent actions, an intent filter can declare zero or more  <action> elements. 
去指定接收的intent action,一个intent filter可以声明零或者更多的<action>
 
To specify accepted intent categories, an intent filter can declare zero or more  <category>
去指定接收的category,一个intent filter可以声明零或者更多的<category>
elements
 
To specify accepted intent data, an intent filter can declare zero or more  <data> elements
去指定接收的intent data,一个intentfilter可以声明零或者多个<data>
 
Each  <data> element can specify a URI structure and a data type (MIME media type). There are
每个<data>可以声明一个URI结构和一个数据类型。
 
 separate attributes —  schemehostport, and  path — for each part of the URI:
这里是一些分解的属性
 
<scheme>://<host>:<port>/<path>

For example:

content://com.example.project:200/folder/subfolder/etc
 
 
If the filter does not list any actions, there is nothing for an intent 
如果filter没有列出任何action,这里就没有什么让一个intent去匹配
 
to match, so all intents fail the test. However, if an Intent does not 
所以所有的intent都不会通过intent filter。然而,如果一个intent没有定义一个
 
specify an action, it will pass the test (as long as the filter contains 
action,它会通过intent filter。(只要filter包含至少一个action)
 
at least one action).
 
For an intent to pass the category test, every category in the  Intent 
对于一个intent去通过category,每个在intent中的category一定要match一个在
 
must match a category in the filter. The reverse is not necessary—the 
intent filter中的category。相反则不需要,intent filter可能比通过intent filter的
 
intent filter may declare more categories than are specified in the 
intent定义多个category
 
Intent and the  Intent will still pass. Therefore, an intent with no 
然而,一个没有category的intent不管intent filter中定义的是什么category,
 
categories should always pass this test, regardless of what categories 
总会通过category过滤。
 
are declared in the filter.
 
Note: Android automatically applies the the  CATEGORY_DEFAULT category to 
注意: 安卓自动为所有隐式的intent应用CATEGORY_DEFAULTcategory
 
all implicit intents passed to  startActivity() and 
通过startActivity()和startActivityForResult()
 
startActivityForResult(). So if you want your activity to receive 
所以如果你想让你的activity接受隐式的意图,它一定要在它的intent filter包含一
 
implicit intents, it must include a category for
个"android.intent.category.DEFAULT" 的category 
 
"android.intent.category.DEFAULT" in its intent filters (as shown in the 
(像上一个例子中展示的一样)
 
previous  <intent-filter> example.
 
 
意图和意图过滤器
 
 
过滤时,只考虑一个Intent与一个Intent filter匹配
            < intent-filter >
                 < action  android:name = "android.intent.action.MAIN"  />
 
                 < category  android:name = "android.intent.category.LAUNCHER"  />
             </ intent-filter >
 
             <!-- TODO - Add necessary intent filter information so that this
                               Activity will accept Intents with the
                               action "android.intent.action.VIEW" and with an "http"
                               schemed URL -->
             < intent-filter >
                 < action  android:name = "android.intent.action.VIEW"  />
                 < category  android:name = "android.intent.category.DEFAULT"  />
                 < data  android:scheme = "http"  />
                </ intent-filter >
如,如果第一个Intent filter中有 <  category   android:name  = "android.intent.category.DEFAULT"  />而第二个Intent filter没有,则在匹配第二个intent Filter时,第一个的 <  category   android:name  = "android.intent.category.DEFAULT"  />不起作用。也就是说,如果manifest
 
            <  intent-filter >
                 <  action   android:name  = "android.intent.action.MAIN"  />
                 <  category   android:name  = "android.intent.category.DEFAULT"  />
                 <  category   android:name  = "android.intent.category.LAUNCHER"  />
             </  intent-filter >
 
             <!-- TODO - Add necessary intent filter information so that this
                               Activity will accept Intents with the
                               action "android.intent.action.VIEW" and with an "http"
                               schemed URL -->
             <  intent-filter >
                 <  action   android:name  = "android.intent.action.VIEW"  />
                
                 <  data   android:scheme  = "http"  />
                </  intent-filter >
则intent不能和第二个Intent filter匹配。

转载于:https://www.cnblogs.com/Steve-Kale/p/3863265.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值