• 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匹配。
  • 相关阅读:
    3.29上午
    3.28下午
    3.28上午
    3.27下午
    3.24的下午
    2017.3.16上午学习内容
    2017.3.15上午学习内容
    2017.3.14下午学习内容
    2017.3.14上午学习内容
    2017.3.13下午学习内容
  • 原文地址:https://www.cnblogs.com/Steve-Kale/p/3863265.html
Copyright © 2020-2023  润新知