GVKun编程网logo

android – 如何使用具有特定参数值的intent-filter捕获URL(安卓获取intent参数)

13

本文将分享android–如何使用具有特定参数值的intent-filter捕获URL的详细内容,并且还将对安卓获取intent参数进行详尽解释,此外,我们还将为大家带来关于AndroidIntent

本文将分享android – 如何使用具有特定参数值的intent-filter捕获URL的详细内容,并且还将对安卓获取intent参数进行详尽解释,此外,我们还将为大家带来关于Android Intent and Intent Filter、Android Intent Filter zip、Android Intent 和 IntentFilter、Android intent-filter pathPattern的相关知识,希望对你有所帮助。

本文目录一览:

android – 如何使用具有特定参数值的intent-filter捕获URL(安卓获取intent参数)

android – 如何使用具有特定参数值的intent-filter捕获URL(安卓获取intent参数)

我试图使用intent-filter拦截QR码上的URL格式:
https://qx.process.com?f=anyValue
也就是说,如果将指定的URL指定为’f =’参数,我只想拦截它.
我试过这个,但它不起作用:

<intent-filter>
<action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.broWSABLE"></category>
    <data android:scheme="https"  android:host="qx.process.com" 
               android:pathPrefix="\\?f=*">
    </data>
</intent-filter>

解决方法

路径只涉及路径而不是像你的XXXX那样的queryString

Android Intent and Intent Filter

Android Intent and Intent Filter

Intents and Intent Filters

 

三种应用程序基本组件 ——activity, service 和 broadcast receiver—— 是使用称为 intent 的消息来激活的。Intent 消息传递是一种组件间运行时绑定的机制. intent 是 Intent 对象,它包含了需要做的操作的描述,或者,对于广播来说,包含了正在通知的消息内容。对于向这三种组件发送 intent 有不同的机制:

  • 使用 Context.startActivity() 或 Activity.startActivityForResult (), 传入一个 intent 来启动一个 activity. 使用 Activity.setResult(), 传入一个 intent 来从 activity 中返回结果.
  • 将 intent 对象传给 Context.startService() 来启动一个 service 或者传消息给一个运行的 service. 将 intent 对象传给 Context.bindService() 来绑定一个 service.
  • 将 intent 对象传给 Context.sendBroadcast()Context.sendOrderedBroadcast(), 或者 Context.sendStickyBroadcast() 等广播方法,则它们被传给 broadcast receiver.

 

在上述三种情况下,android 系统会自己找到合适的 activity, service, 或者  broadcast receivers 来响应 intent. 三者的 intent 相互独立互不干扰.

 

Intent Objects Intent 对象

 

一个 intent 对象包含了接受该 intent 的组件的信息 (例如需要的动作和该动作需要的数据) 和 android 系统所需要的信息 (例如该组件的类别,以及如何启动它). 具体的说:

组件名称
为一个 ComponentName 对象。它是目标组件的完整名 (例如 " com.example.project.app.FreneticActivity") 和应用程序 manifest 文件设定的包名 (例如" com.example.project") 的组合。前者的包名部分和后者不一定一样.

 

组件名称是可选的。如果设定了的话,Intent 对象会被传给指定的类的一个实例。如果不设定,则 android 使用其它信息来定位合适的目标.

 

组件名称是使用 setComponent()setClass(), 或  setClassName() 来设定,使用 getComponent() 来获取.

Action
一个字符串,为请求的动作命名,或者,对于 broadcast intent, 发生的并且正在被报告的动作。例如:
常量 目标组件
动作
ACTION_CALL activity 发起一个电话呼叫.
ACTION_EDIT activity 显示数据给用户来编辑.
ACTION_MAIN activity 将该 activity 作为一个 task 的第一个 activity 启动,不传入参数也不期望返回值.
ACTION_SYNC activity 将设备上的数据和一个服务器同步.
ACTION_BATTERY_LOW broadcast receiver 发出电量不足的警告.
ACTION_HEADSET_PLUG broadcast receiver 一个耳机正被插入或者拔出.
ACTION_SCREEN_ON broadcast receiver 屏幕被点亮.
ACTION_TIMEZONE_CHANGED broadcast receiver 时区设置改变.

 

你也可以定义自己的 action 字符串用来启动你的应用程序。自定义的 action 应该包含应用程序的包名。例如 "com.example.project.SHOW_COLOR".

 

action 很大程度上决定了 intent 的另外部分的结构,就像一个方法名决定了它接受的参数和返回值一样。因此,最好给 action 一个最能反映其作用的名字.

 

一个 intent 对象中的 action 是使用 getAction () 和 setAction () 来读写的.

Data
需要操作的数据的 URI 和它的 MIME (多用途互联网邮件扩展,Multipurpose Internet Mail Extensions) 类型。例如,如果 action 为 ACTION_EDIT, 那么 Data 将包含待编辑的数据 URI. 如果 action 为 ACTION_CALL, Data 将为 tel: 电话号码的 URI. 如果 action 为 ACTION_VIEW, 则 Data 为 http: 网络地址的 URI.

 

当将一个 intent 和一个组件相匹配时,除了 URI 外数据类型也很重要。例如,一个显示图片的程序不应该用来处理声音文件.

 

数据类型常常可以从 URI 推断,特别是 content:URI, 它表示该数据属于一个 content provider. 但数据类型也可以被 intent 对象显示声明. setData () 方法设置 URI, 而 setType () 方法指定 MIME 类型,setDataAndType () 设置数据 URI 和 MIME 类型。它们可以使用 getData () 和 getType () 来读取.

Category
一个字符串,包含了关于处理该 intent 的组件的种类的信息。一个 intent 对象可以有任意个 category. intent 类定义了许多 category 常数,例如:
常量 含义
CATEGORY_BROWSABLE 目标 activity 可以使用浏览器来显示 - 例如图片或电子邮件消息.
CATEGORY_GADGET 该 activity 可以被包含在另外一个装载小工具的 activity 中.
CATEGORY_HOME 该 activity 显示主屏幕,也就是用户按下 Home 键看到的界面.
CATEGORY_LAUNCHER 该 activity 可以作为一个任务的第一个 activity, 并且列在应用程序启动器中.
CATEGORY_PREFERENCE 该 activity 是一个选项面板.

 

 

addCategory () 方法为一个 intent 对象增加一个 category, removeCategory 删除一个 category, getCategories () 获取 intent 所有的 category.

Extras
为键 - 值对形式的附加信息。例如 ACTION_TIMEZONE_CHANGED 的 intent 有一个 "time-zone" 附加信息来指明新的时区,而 ACTION_HEADSET_PLUG 有一个 "state" 附加信息来指示耳机是被插入还是被拔出.

 

intent 对象有一系列 put...() 和 set...() 方法来设定和获取附加信息。这些方法和 Bundle 对象很像。事实上附加信息可以使用 putExtras () 和 getExtras () 作为 Bundle 来读和写.

Flags

各种标志。很多标志指示 android 系统如何启动一个 activity (例如该 activity 属于哪个任务) 和启动后如何处理它 (例如,它是否属于最近 activity 列表中).

 

android 系统和应用程序使用 intent 对象来送出系统广播和激活系统定义的组件.

Intent Resolution Intent 解析

 

intent 有两种:

  • 显式 intent 使用名字来指定目标组件。由于组件名称一般不会被其它开发者所熟知,这种 intent 一般用于应用程序内部消息 -- 例如一个 activity 启动一个附属的 service 或者另一个 activity.
  • 隐式 intent 不指定目标的名称。一般用于启动其它应用程序的组件.

Android 将显式 intent 发送给指定的类. intent 对象中名字唯一决定接受 intent 的对象.

 

对于隐式 intent, android 系统必须找到最合适的组件来处理它。它比较 intent 的内容和 intent filter.  intent filter 是组件的一个相关结构,表示其接受 intent 的能力. android 系统根据 intent filter 打开可以接受 intent 的组件。如果一个组件没有 intent filter, 那么它只能接受显式 intent. 如果有,则能同时接受二者.

当一个 intent 和 intent filter 比较时,只考虑三个属性: action, data, category.

extra 和 flag 在 intent 解析中没有用.

Intent filters

 

activity, service 和 broadcast receiver 可以有多个 intent filter 来告知系统它们能接受什么样的隐式 intent. intent filter 的名字很形象:它过滤掉不想接受的 intent, 留下想接受的 intent. 显式 intent 无视 intent filter.

一个组件对能做的每件事有单独的 filter. 例如,记事本程序的 NoteEditor activity 有两个 filter -- 一个启动并显示一个特定的记录给用户查看或编辑,另一个启动一个空的记录给用户编辑.

 

Filters and security Filter 和安全

 

一个 intent filter 不一定安全可靠。一个应用程序可以让它的某个组件去接受隐式 intent, 但是它没法防止这个组件接受显示 intent. 其它的程序总是可以使用自定义的数据加上显式的程序名称来调用该组件.

 

一个 intent filter 是 IntentFilter 类的实例,但是它一般不出现在代码中,而是出现在 android Manifest 文件中,以 <intent-filter> 的形式. (有一个例外是 broadcast receiver 的 intent filter 是使用 Context.registerReceiver() 来动态设定的,其 intent filter 也是在代码中创建的.)

一个 filter 有 action, data, category 等字段。一个隐式 intent 为了能被某个 intent filter 接受,必须通过 3 个测试。一个 intent 为了被某个组件接受,则必须通过它所有的 intent filter 中的一个.

 

Action 测试
<intent-filter . . . >
    
<action android:name="com.example.project.SHOW_CURRENT" />
    
<action android:name="com.example.project.SHOW_RECENT" />
    
<action android:name="com.example.project.SHOW_PENDING" />
    . . .
</intent-filter>

 

 

一个 intent 对象只能指定一个 action, 而一个 intent filter 可以指定多个 action. action 列表不能为空,否则它将组织所有的 intent.

 

一个 intent 对象的 action 必须和 intent filter 中的某一个 action 匹配,才能通过.

如果 intent filter 的 action 列表为空,则不通过.

如果 intent 对象不指定 action, 并且 intent filter 的 action 列表不为空,则通过.

Category 测试

<intent-filter . . . >

    <category android:name="android.intent.category.DEFAULT" />
    
<category android:name="android.intent.category.BROWSABLE" />
    . . .
</intent-filter>

 

 

注意前面说到的对于 action 和 category 的常数是在代码中用的,而不是 manifest 文件中用的。例如,CATEGORY_BROWSABLE 常数对应 xml 中的表示为 "android.intent.category.BROWSABLE".

一个 intent 要通过 category 测试,那么该 intent 对象中的每个 category 都必须和 filter 中的某一个匹配.

 

理论上来说,一个 intent 对象如果没有指定 category 的话,它应该能通过任意的 category 测试。有一个例外: android 把所有的传给 startActivity () 的隐式 intent 看做至少有一个 category: "android.intent.category.DEFAULT". 因此,想要接受隐式 intent 的 activity 必须在 intent filter 中加入"android.intent.category.DEFAULT". ("android.intent.action.MAIN"和"android.intent.category.LAUNCHER"的 intent filter 例外。它们不需要"android.intent.category.DEFAULT".)


Data test
<intent-filter . . . >
    
<data android:mimeType="video/mpeg" android:scheme="http" . . . />
    
<data android:mimeType="audio/mpeg" android:scheme="http" . . . />
    . . .
</intent-filter>

 

 

每个 <data> 元素指定了一个 URI 和一个数据类型. URI 每个部分为不同的属性 -- scheme, host, port, path:

scheme://host:port/path

例如,在如下的 URI 中:

content://com.example.project:200/folder/subfolder/etc

 

scheme 为 "content", host 为 "com.example.project", port 为 "200", path 为 "folder/subfolder/etc". host 和 port 一起组成了 URI authority. 如果 host 未指定,则 port 被忽略.

 

这些属性都是可选的,但它们并非相互独立:要使一个 authority 有意义,必须指定一个 scheme. 要使一个 path 有意义,必须指定一个 scheme 和一个 authority.

 

当 intent 对象中的 URI 和 intent filter 中相比较时,它只和 filter 中定义了的部分比较。例如,如果 filter 中之定义了 scheme, 那么所有包含该 scheme 的 URI 的 intent 对象都通过测试。对于 path 来说,可以使用通配符来进行部分匹配.

<data> 元素的 type 属性指定了数据类型。它在 filter 中比在 URI 中更常见. intent 对象和 filter 都可以使用 "*" 通配符作为子类型。例如 "text/*" "audio/*" 表示所有的子类型都匹配.

 

data 测试的规则如下:

  1. 一个不含 uri 也不含数据类型的 intent 对象只通过两者都不包含的 filter.
  2. 一个含 uri 但不含数据类型的 intent 对象 (并且不能从 uri 推断数据类型的) 只能通过这样的 filter: uri 匹配,并且不指定类型。这种情况限于类似 mailto: 和 tel: 这样的不指定实际数据的 uri.
  3. 一个只包含数据类型但不包含 URI 的 intent 只通过这样的 filter: 该 filter 只列出相同的数据类型,并且不指定 uri.
  4. 一个既包含 uri 又包含数据类型的 intent 对象只通过这样的 filter: intent 对象的数据类型和 filter 中的一个类型匹配,intent 对象的 uri 要么和 filter 的 uri 匹配,要么 intent 对象的 uri 为 content: 或者 file:, 并且 filter 不指定 uri.

 

如果一个 intent 可以通过多于一个 activity 或者 service 的 filter, 那么用户可能会被询问需要启动哪一个。如果一个都没有的话,那么会抛出异常.

Common cases 常见情况

 

上述的最后一个规则 (d) 说明了组件通常可以从文件和 content provider 中获取数据。因此,它们的 filter 可以只列出数据类型不列 scheme. 这是个特殊情况。下列 < data > 元素告诉 android 该组件可以从一个 content provider 取得图像数据并显示之:

<data android:mimeType="image/*" />

 

由于大部分可用的数据由 content provider 提供,指定数据类型但不指定 uri 的 filter 是最常见的情况.

 

另外一个常见的配置是 filter 具有一个 scheme 和一个数据类型。例如,下列 <data> 元素告诉 android 该 component 可以从网络获取图像数据并显示之:

<data android:scheme="http" android:type="video/*" />

 

考虑用户点击一个网页时浏览器的动作。它首先试图显示这个数据 (当做一个 html 页来处理). 如果无法显示,则创建一个隐式 intent, 并启动一个可以处理它的 activity. 如果没有这样的 activity, 那么它请求下载管理器来下载该数据。然后它将数据置于一个 content provider 的控制之下,这样有很多 activity (拥有只有数据类型的 filter) 可以处理这些数据.

 

大部分应用程序还有一种方法来单独启动,不需要引用任何特定的数据。这些能启动应用程序的 activity 具有 action 为 "android.intent.action.MAIN"的 filter. 如果它们需要在应用程序启动器中显示,它们必须指定"android.intent.category.LAUNCHER" 的 category.

<intent-filter . . . >
    
<action android:name="code android.intent.action.MAIN" />
    
<category android:name="code android.intent.category.LAUNCHER" />
</intent-filter>

Using intent matching 使用 intent 匹配

 

intent 和 intent filter 相匹配,不仅为了寻找并启动一个目标组件,也是为了寻找设备上组件的信息。例如,android 系统启动了应用程序启动器,该程序位于屏幕的顶层,显示了用户可以启动的程序,这是通过查找设备上所有的 action 为 "android.intent.action.MAIN",category 为"android.intent.category.LAUNCHER"的 intent filter 所在的 activity 实现的。然后它显示了这些 activity 的图标和标题。类似的,它通过寻找"android.intent.category.HOME" 的 filter 来定位主屏幕程序.

 

应用程序可以用相同的方式来使用 intent 匹配. PackageManager 有一组 query...() 方法来寻找接受某个特定 intent 的所有组件,还有一系列 resolve...() 方法来决定响应一个 intent 的最佳组件。例如, queryIntentActivities() 返回一个 activity 列表,这些 activity 可以执行传入的 intent. 类似的还有 queryIntentServices () 和 queryIntentBroadcastReceivers ().

Note Pad Example 例子:记事本

 

记事本示例程序让用户可以浏览一个笔记列表,查看,编辑,删除和增加笔记。这一节关注该程序定义的 intent filter.

 

 

在其 manifest 文件中,记事本程序定义了三个 activity, 每个有至少一个 intent filter. 它还定义了一个 content provider 来管理笔记数据. manifest 文件如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          
package="com.example.android.notepad">
    
<application android:icon="@drawable/app_notes"
                 
android:label="@string/app_name" >

        
<provider android:name="NotePadProvider"
                  
android:authorities="com.google.provider.NotePad" />

        
<activity android:name="NotesList" android:label="@string/title_notes_list">
            
<intent-filter>
                
<action android:name="android.intent.action.MAIN" />
                
<category android:name="android.intent.category.LAUNCHER" />
            
</intent-filter>
            
<intent-filter>
                
<action android:name="android.intent.action.VIEW" />
                
<action android:name="android.intent.action.EDIT" />
                
<action android:name="android.intent.action.PICK" />
                
<category android:name="android.intent.category.DEFAULT" />
                
<data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
            
</intent-filter>
            
<intent-filter>
                
<action android:name="android.intent.action.GET_CONTENT" />
                
<category android:name="android.intent.category.DEFAULT" />
                
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            
</intent-filter>
        
</activity>
        
        
<activity android:name="NoteEditor"
                  
android:theme="@android:style/Theme.Light"
                  
android:label="@string/title_note" >
            
<intent-filter android:label="@string/resolve_edit">
                
<action android:name="android.intent.action.VIEW" />
                
<action android:name="android.intent.action.EDIT" />
                
<action android:name="com.android.notepad.action.EDIT_NOTE" />
                
<category android:name="android.intent.category.DEFAULT" />
                
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            
</intent-filter>
            
<intent-filter>
                
<action android:name="android.intent.action.INSERT" />
                
<category android:name="android.intent.category.DEFAULT" />
                
<data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
            
</intent-filter>
        
</activity>
        
        
<activity android:name="TitleEditor"
                  
android:label="@string/title_edit_title"
                  
android:theme="@android:style/Theme.Dialog">
            
<intent-filter android:label="@string/resolve_title">
                
<action android:name="com.android.notepad.action.EDIT_TITLE" />
                
<category android:name="android.intent.category.DEFAULT" />
                
<category android:name="android.intent.category.ALTERNATIVE" />
                
<category android:name="android.intent.category.SELECTED_ALTERNATIVE"/>
                
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            
</intent-filter>
        
</activity>
        
    
</application>
</manifest>

 

第一个 activity, NoteList, 和其它 activity 不同,因为它操作一个笔记的目录 (笔记列表), 而不是一个单独的笔记。它一般作为该程序的初始界面。它可以做以下三件事:

  1. <intent-filter>
        
    <action android:name="android.intent.action.MAIN" />
        
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    该 filter 声明了记事本应用程序的主入口。标准的 MAIN action 是一个不需要任何其它信息 (例如数据等) 的程序入口,LAUNCHER category 表示该入口应该在应用程序启动器中列出.

  2. <intent-filter>
        
    <action android:name="android.intent.action.VIEW" />
        
    <action android:name="android.intent.action.EDIT" />
        
    <action android:name="android.intent.action.PICK" />
        
    <category android:name="android.intent.category.DEFAULT" />
        
    <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
    </intent-filter>

    该 filter 声明了改 activity 可以对一个笔记目录做的事情。它允许用户查看或编辑该目录 (使用 VIEW 和 EDIT action), 或者选取特定的笔记 (使用 PICK action).

    <data> 元素的 mimeType 指定了这些 action 可以操作的数据类型。它表明该 activity 可以从一个持有记事本数据的 content provider (vnd.google.note) 取得一个或多个数据项的 Cursor (vnd.android.cursor.dir).

    注意该 filter 提供了一个 DEFAULT category. 这是因为 Context.startActivity() 和 Activity.startActivityForResult () 方法将所有的 intent 都作为作为包含了 DEFAULT category 来处理,只有两个例外:

    • 显式指明目标 activity 名称的 intent.
    • 包含 MAIN action 和 LAUNCHER category 的 intent.

    因此,除了 MAIN 和 LAUNCHER 的 filter 之外,DEFAULT category 是必须的.

  3. <intent-filter>
        
    <action android:name="android.intent.action.GET_CONTENT" />
        
    <category android:name="android.intent.category.DEFAULT" />
        
    <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
    </intent-filter>

    这个 filter 描述了该 activity 能够在不需要知道目录的情况下返回用户选择的一个笔记的能力. GET_CONTENT action 和 PICK action 相类似。在这两者中,activity 都返回用户选择的笔记的 URI. (返回给调用 startActivityForResult () 来启动 NoteList activity 的 activity.) 在这里,调用者指定了用户选择的数据类型而不是数据的目录.

    这个数据类型, vnd.android.cursor.item/vnd.google.note, 表示了该 activity 可以返回的数据类型 -- 一个笔记的 URI. 从返回的 URI, 调用者可以从持有笔记数据的 content provider (vnd.google.note) 得到一个项目 (vnd.android.cursor.item) 的 Cursor.

    也就是说,对于 PICK 来说,数据类型表示 activity 可以给用户显式的数据类型。对于 GET_CONTENT filter, 它表示 activity 可以返回给调用者的数据类型.

 

下列 intent 可以被 NoteList activity 接受:

action:  android.intent.action.MAIN
不指定任何数据直接启动 activity.

action:  android.intent.action.MAIN
category:  android.intent.category.LAUNCHER
不指定任何数据直接启动 activity. 这是程序启动器使用的 intent. 所有使用该组合的 filter 的 activity 被加到启动器中.

action:  android.intent.action.VIEW
data:  content://com.google.provider.NotePad/notes
要求 activity 显示一个笔记列表,这个列表位于 content://com.google.provider.NotePad/notes. 用户可以浏览这个列表并获取列表项的信息.

action:  android.intent.action.PICK
data:  content://com.google.provider.NotePad/notes
请求 activity 显示 content://com.google.provider.NotePad/notes 下的笔记列表。用户可以选取一个笔记,activity 将返回笔记的 URI 给启动 NoteList 的 activity.

action:  android.intent.action.GET_CONTENT
data type:  vnd.android.cursor.item/vnd.google.note
请求 activity 提供记事本数据的一项.

 

 

第二个 activity, NoteEditor, 为用户显示一个笔记并允许他们编辑它。它可以做以下两件事:

  1. <intent-filter android:label="@string/resolve_edit">
        
    <action android:name="android.intent.action.VIEW" />
        
    <action android:name="android.intent.action.EDIT" />
        
    <action android:name="com.android.notepad.action.EDIT_NOTE" />
        
    <category android:name="android.intent.category.DEFAULT" />
        
    <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
    </intent-filter>

    这个 activity 的主要目的是使用户编辑一个笔记 --VIEW 或者 EDIT 一个笔记. (在 category 中,EDIT_NOTE 是 EDIT 的同义词.) intent 包含匹配 MIME 类型 vnd.android.cursor.item/vnd.google.note 的 URI-- 也就是某一个特定的笔记的 URI. 它一般来说是 NoteList activity 中的 PICK 或者 GET_CONTENT action 返回的.

    像以前一样,该 filter 列出了 DEFAULT category.

  2. <intent-filter>
        
    <action android:name="android.intent.action.INSERT" />
        
    <category android:name="android.intent.category.DEFAULT" />
        
    <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
    </intent-filter>

    该 activity 的第二个目的是使用户能够创建一个新的笔记,并插入到已存在的笔记目录中。该 intent 包含了匹配 vnd.android.cursor.dir/vnd.google.note 的 URI, 也就是笔

 

有了这些能力,NoteEditor 就可以接受以下 intent:

action:  android.intent.action.VIEW
data:  content://com.google.provider.NotePad/notes/ID
要求 activity 显示给定 ID 的笔记.

action:  android.intent.action.EDIT
data:  content://com.google.provider.NotePad/notes/ID
要求 activity 显示指定 ID 的笔记,然后让用户来编辑它。如果用户保存了更改,则 activity 更新该 content provider 的数据.

action:  android.intent.action.INSERT
data:  content://com.google.provider.NotePad/notes
要求 activity 创建一个新的空笔记在 content://com.google.provider.NotePad/notes, 并允许用户编辑它,如果用户保存了更改,则该 URI 被返回给调用者.

最后一个 activity, TitleEditor, 允许用户编辑笔记的标题。这可以通过直接调用 activity (在 intent 中设置组件名称) 的方式来实现。但是这里我们用这个机会来展示如何在已有数据上进行另外的操作 (类似于 windows 中的打开方式 -> 程序列表 -- 译者注):

<intent-filter android:label="@string/resolve_title">
    
<action android:name="com.android.notepad.action.EDIT_TITLE" />
    
<category android:name="android.intent.category.DEFAULT" />
    
<category android:name="android.intent.category.ALTERNATIVE" />
    
<category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
    
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>
它必须在一个特定的笔记上调用 (data type  vnd.android.cursor.item/vnd.google.note), 就像之前的 VIEWEDIT action 一样。然而,这里 activity 显示笔记数据中包含的标题,而不是内容.

 

除了支持 DEFAULT category 之外,title 编辑器还支持了另外两个 category: ALTERNATIVE SELECTED_ALTERNATIVE. 这些 category 标志着 activity 可以在选项菜单中呈现给用户 (就像 LAUNCHER category 表示 activity 可以在程序启动器中一样). 注意 filter 还提供了一个显示标签 (android:label="@string/resolve_title") 来更好的控制用户在选项菜单中看到的内容.

 

有了这些能力,以下的 intent 就可以被 TitleEditor 接受:

action:  com.android.notepad.action.EDIT_TITLE
data:  content://com.google.provider.NotePad/notes/ID
要求 activity 显示给定笔记 ID 的标题,并允许用户编辑该标题.

http://blog.csdn.net/lmhit/article/details/5576250

Android Intent Filter zip

Android Intent Filter zip

我想使用一个Intent过滤器,当在fileexplorer中单击一个zip文件时,它会打开应用程序

所以我必须使用哪种mimetype?
以及获得路径的代码?

<activity
    android:name=".App"
    android:label="@string/app_name" >
    <intent-filter>
      <action android:name="android.intent.action.SEND" />

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

      <data android:mimeType="text/plain" />

    </intent-filter>

    </activity>

Java的代码:

Intent intent = getIntent();

        // To get the action of the intent use
        String action = intent.getAction();
        if (action != Intent.ACTION_SEND) {
            throw new RuntimeException("Should not happen");
        }
        // To get the data use
        Uri data = intent.getData();
        URL url;
        try {
            url = new URL(data.getPath());
        } catch (MalformedURLException e) {
            // Todo Auto-generated catch block
            e.printstacktrace();
        }

解决方法:

您可以使用以下IntentFilter:

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

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

    <data android:mimeType="application/zip"/>
</intent-filter>

当您的Activity启动时,它有一个数据URI,您可以从中获取zip文件:

File zip = new File(getIntent().getData().getPath());

Android Intent 和 IntentFilter

Android Intent 和 IntentFilter

OSC 请你来轰趴啦!1028 苏州源创会,一起寻宝 AI 时代

Intent:

Intent 是 Android 不同组件间通信的载体。

显示 Intent:主要根据组件类名来的

显示 IntentFilter:主要根据某些条件来作为触发的条件,通过 IntentFilter 来声明条件

Android intent-filter pathPattern

Android intent-filter pathPattern

我想制作一个可以检测这样的网址的intent-filter:

http://192.168.0.xx/playlist/_definst_/iphone.smil/list.m3u8?token=XXXXXXX

到目前为止我试过这个,但没有运气.

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

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

        <data
            android:host="*"
            android:pathPattern=".*\\*.m3u8.*"
            android:scheme="http" />
    </intent-filter>

我错过了什么?
需要你的帮助.
这对我有用.希望它也有助于其他人.

 <data android:scheme="http" android:host="*"
            android:pathPattern=".*\\.m3u8" />
        <data android:scheme="http" android:host="*"
            android:pathPattern=".*\\..*\\.m3u8" />
        <data android:scheme="http" android:host="*"
            android:pathPattern=".*\\..*\\..*\\..m3u8" />
        <data android:scheme="http" android:host="*"
            android:pathPattern=".*\\..*\\..*\\..*\\.m3u8" />

解决方法:

试试这个,

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.broWSABLE" />
    <data android:scheme="http" />
    <data android:host="*" />
    <data android:mimeType="*/*" />
    <data android:pathPattern="*.*\\.m3u8" />
</intent-filter>

或者,有了这个

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />        
    <category android:name="android.intent.category.broWSABLE" />        
    <data android:scheme="http" />
    <data android:host="*" />
    <data android:pathPattern=".*\\.m3u8" />
</intent-filter>

这有效:

     <data android:scheme="http" android:host="*"
            android:pathPattern=".*\\.m3u8" />
        <data android:scheme="http" android:host="*"
            android:pathPattern=".*\\..*\\.m3u8" />
        <data android:scheme="http" android:host="*"
            android:pathPattern=".*\\..*\\..*\\..m3u8" />
        <data android:scheme="http" android:host="*"
            android:pathPattern=".*\\..*\\..*\\..*\\.m3u8" />

关于android – 如何使用具有特定参数值的intent-filter捕获URL安卓获取intent参数的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Android Intent and Intent Filter、Android Intent Filter zip、Android Intent 和 IntentFilter、Android intent-filter pathPattern等相关知识的信息别忘了在本站进行查找喔。

本文标签: