WEB开发网
开发学院手机开发Android 开发 Android SDK 开发之 Intent 和 Intent Filter 阅读

Android SDK 开发之 Intent 和 Intent Filter

 2010-03-23 04:12:00 来源:WEB开发网   
核心提示:filter中加入"android.intent.category.DEFAULT". ("android.intent.action.MAIN" 和"android.intent.category.LAUNCHER"的intent filter例外. 它们不
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.

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:Android SDK 开发

编辑录入:coldstar [复制链接] [打 印]
赞助商链接