Enjoy yourself,and don't care about others' thinking!
----TiGERTiAN
BlogJava
首頁
新隨筆
聯(lián)系
聚合
管理
隨筆-348 評論-598 文章-0 trackbacks-0
Android的Intent和IntentFilter應(yīng)用說明一例
很多人對文檔中的Intent和IntentFilter不理解是什么意思,我這里舉例解釋下。
Intent字面意思就是目標(biāo),目的。通俗一點,需要達(dá)成某些目標(biāo),則需要提供一些動作,這些目標(biāo)的分類,以及達(dá)成這些目標(biāo)所需要的一些數(shù)據(jù)等等。Android中的Intent通過Action,Category和data等屬性進(jìn)行了相應(yīng)的描述,我們想做某些事情(達(dá)成某些目標(biāo)),就需要填寫這些參數(shù)的部分或全部,這樣Android才會幫助我們自動的去進(jìn)行某些操作。
IntentFilter是配合Intent而生的,你有目標(biāo)行動或者結(jié)果,那么那些行動和結(jié)果就會有他完成的特定要求,這些要求就是IntentFilter,可以理解為Intent和IntentFilter是相對應(yīng)的。
<
activity
android:name
=".TestService"
android:label
="@string/app_name"
>
<
intent-filter
>
<
action
android:name
="android.intent.action.MAIN"
/>
<
category
android:name
="android.intent.category.LAUNCHER"
/>
<
action
android:name
="android.intent.action.STORE_REQUEST"
></
action
>
<
category
android:name
="android.intent.category.ALTERNATIVE"
/>
<
category
android:name
="android.intent.category.SELECTED_ALTERNATIVE"
/>
</
intent-filter
>
<
intent-filter
>
<
action
android:name
="android.intent.action.TIGERTIAN"
></
action
>
<
category
android:name
="android.intent.category.DEFAULT"
></
category
>
<
data
android:scheme
="x-id"
></
data
>
</
intent-filter
>
<
intent-filter
>
<
action
android:name
="android.intent.action.EDIT"
></
action
>
<
category
android:name
="android.intent.category.DEFAULT"
></
category
>
<
category
android:name
="android.intent.category.BROWSABLE"
></
category
>
</
intent-filter
>
</
activity
>
上面的Activity有三個Filter,第一個是給Android系統(tǒng)用的,表示這個Activity可以顯示在桌面上(Launcher中)。同時Alternative表明,這個Activity可以
變成OptionMenu,供其他Activity直接調(diào)用。
后面兩個Filter就是我自定義的了,第二個Filter可以在其他Activity中用如下方法直接調(diào)用:
Uri uri
=
Uri.parse(
"
x-id://www.google.com/getDetails?id=123
"
);
Intent in
=
new
Intent();
in.setAction(
"
android.intent.action.TIGERTIAN
"
);
in.addCategory(Intent.CATEGORY_DEFAULT);
in.setData(uri);
//
in.setClassName("com.tigertian.service", "com.tigertian.service.TestService");
TestActivity.
this
.startActivity(in);
在Filter配置中CATEGORY_DEFAULT是不可缺少的,想調(diào)用這個Service,可以不指定Class,但其他條件必須匹配(CATEGORY_DEFAULT可以不設(shè)置,Android默認(rèn)會自動加上),通過Action,category和data就可以調(diào)用相應(yīng)的Activity了,這是Android幫你做的,當(dāng)然如果系統(tǒng)中存在多個匹配這些條件的Activity或者Service,Android根據(jù)優(yōu)先級進(jìn)行調(diào)用。
第三個調(diào)用方式如下:
Uri uri
=
Uri.parse(
"
x-id://www.google.com/getDetails?id=123
"
);
Intent in
=
new
Intent();
in.setAction(Intent.ACTION_EDIT);
in.addCategory(Intent.CATEGORY_BROWSABLE);
//
in.setData(uri);
//
in.setComponent(new ComponentName("com.tigertian.service", "com.tigertian.service.TestService"));
TestActivity.
this
.startActivity(in);
看到?jīng)]有?可以不指定CATEGORY_DEFAULT,Android自動幫你添加。就是這么簡單。
---------------------------------------------------------
專注移動開發(fā)
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2010-02-03 18:01
TiGERTiAN
閱讀(37703)
評論(11)
編輯
收藏
所屬分類:
Java
、
Android
評論:
#
re: Android的Intent和IntentFilter應(yīng)用說明一例 2010-09-16 17:30 |
講的什么東西!!
IntentFilter是配合Intent而生的,你有目標(biāo)行動或者結(jié)果,那么那些行動和結(jié)果就會有他完成的特定要求,這些要求就是IntentFilter,可以理解為Intent和IntentFilter是相對應(yīng)的。
后面的列子也看不懂!
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例 2010-09-16 17:32 |
TiGERTiAN
@ 講的什么東西!!
你一點都不學(xué)習(xí),當(dāng)然看不懂了。
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例 2010-09-16 17:56 |
講的什么東西!!
//in.setClassName("com.tigertian.service", "com.tigertian.service.TestService");
這個東西到底是給我們的提示還是沒有用的東西呀,
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例 2010-09-17 14:26 |
講的什么東西!!
你這個代碼調(diào)不通
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例 2011-03-21 14:55 |
gangbener
你好,我嘗試了之后代碼運(yùn)行均無誤,但是我想要更加明確的運(yùn)行結(jié)果,因為按照上面的代碼運(yùn)行后只能在DDMS中查看可以正常運(yùn)行,但是并不知道在IntentFilter中設(shè)置的屬性是否起作用了。我是在一個Activity中實現(xiàn)的,即,我在一個名為“intentExample”的Activity的intentExample Menifest文件中寫入了上面三個intentfilter,并在該Activity中調(diào)用intentExample.this.startActivity(in)。
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例 2013-02-26 14:30 |
zcmain
精簡干練 頂。。
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例[未登錄] 2013-05-08 23:01 |
wang
垃圾
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例 2013-08-01 15:27 |
魏滋瓏
受益了 謝謝LZ 講的這么詳細(xì)
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例 2013-08-23 16:51 |
awander
簡明!通透!
多謝了!
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例[未登錄] 2013-10-29 16:27 |
lee
@TiGERTiAN
這是從哪里抄的什么東西的,亂七八糟的。
回復(fù)
更多評論
#
re: Android的Intent和IntentFilter應(yīng)用說明一例[未登錄]
2014-11-12 14:24 |
Arlen
大家不明白的就是IntentFilter,而你并沒有舉什么例子,看這評論,大家都看不懂的。。。不過還是多謝分享。
回復(fù)
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關(guān)文章:
OSGi and Hadoop and Node.js
javacc工具小記
MyEclipse 6.5新序列號,到2013年
OtaNotifier.java
Java中無符號整數(shù)
C#的BinaryWriter和Java的DataInputStream之間的數(shù)據(jù)相互轉(zhuǎn)換
在Mac下面下載Android源代碼
[轉(zhuǎn)]Java通過XML Schema校驗XML
[轉(zhuǎn)]JAVA上加密算法的實現(xiàn)用例
LG GW880(Ophone)開啟ADB調(diào)試模式
專注移動開發(fā)--Windows Mobile, Android, iPhone, J2ME, BlackBerry, Symbian, Windows Phone
慢慢混,慢慢學(xué)
<
2010年2月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(43)
給我留言
查看公開留言
查看私人留言
隨筆分類
(402)
Ajax(4)
Android(58)
BlackBerry(8)
C/C++(3)
Design Patterns(6)
Discuz!NT(1)
DotNet(26)
Feeling(61)
Flex(4)
Grails(2)
Hibernate(1)
iPhone(5)
J2ME(11)
Java(99)
JSF(26)
Linux(18)
MapXtreme(9)
Objective c(1)
Oracle(6)
Other technique(20)
Perl/Python(1)
Roller (10)
Symbian
VB/ASP(7)
WebWork(3)
Windows Mobile(10)
WindowsPhone(2)
隨筆檔案
(306)
2017年5月 (1)
2016年8月 (1)
2015年11月 (1)
2015年2月 (1)
2015年1月 (1)
2013年12月 (1)
2013年5月 (1)
2013年4月 (1)
2012年9月 (1)
2012年7月 (1)
2012年6月 (1)
2012年5月 (2)
2012年4月 (1)
2012年2月 (2)
2012年1月 (1)
2011年11月 (2)
2011年10月 (1)
2011年9月 (1)
2011年8月 (2)
2011年7月 (3)
2011年6月 (2)
2011年3月 (3)
2011年2月 (4)
2011年1月 (15)
2010年12月 (1)
2010年11月 (2)
2010年10月 (6)
2010年9月 (12)
2010年8月 (3)
2010年7月 (2)
2010年6月 (6)
2010年5月 (14)
2010年4月 (7)
2010年3月 (16)
2010年2月 (10)
2010年1月 (14)
2009年12月 (12)
2009年11月 (5)
2009年10月 (3)
2009年9月 (2)
2009年8月 (3)
2009年6月 (1)
2009年4月 (2)
2009年3月 (2)
2009年1月 (3)
2008年12月 (3)
2008年11月 (20)
2008年10月 (17)
2008年9月 (3)
2008年4月 (1)
2008年3月 (2)
2008年2月 (8)
2008年1月 (1)
2007年11月 (2)
2007年10月 (13)
2007年9月 (3)
2007年7月 (4)
2007年6月 (2)
2007年5月 (12)
2007年4月 (15)
2007年3月 (6)
2007年2月 (2)
2007年1月 (1)
2006年7月 (2)
2006年4月 (1)
2006年1月 (1)
2005年11月 (1)
2005年8月 (1)
2005年7月 (9)
相冊
我正在讀的書
我的好友們
JavaBy
有心就有翼 有夢就會飛--MC
搜索
積分與排名
積分 - 810805
排名 - 50
最新評論
1.?re: Hibernate三種狀態(tài)的區(qū)分,以及save,update,saveOrUpdate,merge等的使用[未登錄]
哈哈~
--a
2.?re: onInterceptTouchEvent和onTouchEvent調(diào)用時序
@米其林的微笑
在你的子view重寫ontouchevent方法就行
--kxt
3.?re: Android彈出撥號界面和撥打電話實現(xiàn)
這找不到call是怎么回事?現(xiàn)在有別的方法實現(xiàn)這個功能嗎?
--firetomato
4.?re: Android彈出撥號界面和撥打電話實現(xiàn)
請我dial和call方法有什么區(qū)別么?
--jaime
5.?re: Android文字跑馬燈控件(文本自動滾動控件)
如何讓滾動的速度快一點啊??
--學(xué)鳥
閱讀排行榜
1.?onInterceptTouchEvent和onTouchEvent調(diào)用時序(38703)
2.?Android的Intent和IntentFilter應(yīng)用說明一例(37703)
3.?Hibernate三種狀態(tài)的區(qū)分,以及save,update,saveOrUpdate,merge等的使用(34339)
4.?Android中短信攔截解決方案(31086)
5.?Android中ContentProvider和ContentResolver使用入門(21425)
評論排行榜
1.?【JSF】Richfaces復(fù)選框樹(Checkbox tree)的權(quán)限分配的解決方案(69)
2.?JSF中動態(tài)生成HtmlMessage控件出錯的解決辦法(38)
3.?hibernate中at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)異常的解決方法(27)
4.?這兩天用Flex寫了一個多媒體播放器(19)
5.?Android文字跑馬燈控件(文本自動滾動控件)(17)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 TiGERTiAN
主站蜘蛛池模板:
全免费a级毛片免费看
|
国产精品亚洲五月天高清
|
国产成人无码精品久久久免费
|
国产一级淫片视频免费看
|
午夜亚洲国产精品福利
|
又粗又大又长又爽免费视频
|
亚洲av日韩av永久无码电影
|
国产视频精品免费
|
免费看美女午夜大片
|
亚洲性日韩精品一区二区三区
|
国产视频精品免费视频
|
亚洲国产成人高清在线观看
|
99re在线这里只有精品免费
|
亚洲成aⅴ人在线观看
|
成年人视频在线观看免费
|
含羞草国产亚洲精品岁国产精品
|
免费大学生国产在线观看p
|
亚洲精品视频免费
|
亚洲AV福利天堂一区二区三
|
a拍拍男女免费看全片
|
亚洲av无码专区在线电影天堂
|
亚洲视频一区调教
|
国产福利在线观看免费第一福利
|
激情综合亚洲色婷婷五月APP
|
暖暖免费高清日本中文
|
国产久爱免费精品视频
|
91情国产l精品国产亚洲区
|
在线观看特色大片免费视频
|
免费人成视频在线观看免费
|
亚洲乳大丰满中文字幕
|
222www免费视频
|
香蕉视频亚洲一级
|
亚洲av永久无码精品网站
|
免费毛片a在线观看67194
|
边摸边吃奶边做爽免费视频网站
|
亚洲无线码在线一区观看
|
成人免费在线看片
|
ssswww日本免费网站片
|
亚洲一级毛片免费看
|
国产亚洲色婷婷久久99精品91
|
真人做A免费观看
|