<action android:name="android.intent.action.MAIN" /> <category android:name=.....

当前访客身份:游客 [
这个人很懒,啥也没写
:谢谢楼主分享总结!把你的博客看了个遍,总结的真...
今日访问:57
昨日访问:61
本周访问:860
本月访问:723
所有访问:26161
IntentFilter--&Action、Category属性详解
发表于2年前( 17:36)&&
阅读(439)&|&评论()
0人收藏此文章,
如果一个 Intent 请求在一片数据上执行一个动作, Android 如何知道哪个应用程序(和组件)能用来响应这个请求呢? Intent Filter就是 用来注册 Activity 、 Service 和 Broadcast Receiver 具有能在某种数据上执行一个动作的能力。使用 Intent Filter ,应用程序组件告诉 Android ,它们能为其它程序的组件的动作请求提供服务,包括同一个程序的组件、本地的或第三方的应用程序。
为了注册一个应用程序组件为 Intent 处理者,在组件的 manifest 节点添加一个 intent-filter 标签。在 Intent Filter 节点里使用下面的标签(关联属性),你能指定组件支持的动作、种类和数据。
1、动作测试:
&&&&&&&&&activity&android:name="com.x210.intentfilters.OneActivity"&android:label="oneActivity"&&&&
&&&&&&&&&&&&&intent-filter&
&&&&&&&&&&&&&&&&&action&android:name="myapp.action.test1"&/&
&&&&&&&&&&&&&&&&&category&android:name="android.intent.category.DEFAULT"&/&&&
&&&&&&&&&&&&&/intent-filter&
&&&&&&&&&/activity&
规则a.一条&intent-filter&元素至少应该包含一个&action&,否则任何Intent请求都不能和该&intent-filter&匹配。
&&&&&&&&&activity&android:name="com.x210.intentfilters.OtherActivity"&android:label="otherActivity"&&&&
&&&&&&&&&&&&&intent-filter&&&
&&&&&&&&&&&&&&&&&category&android:name="cate1"/&
&&&&&&&&&&&&&&&&&category&android:name="cate2"/&
&&&&&&&&&&&&&&&&&category&android:name="android.intent.category.DEFAULT"&/&&&
&&&&&&&&&&&&&/intent-filter&
&&&&&&&&&/activity&
以上&intent-filter&元素没有包含&action&标签,任何Intent请求都无法与该&intent-filter&匹配。
规则b.如果Intent请求的Action和&intent-filter&中个某一条&action&匹配,那么该Intent就通过了这条&intent-filter&的动作测试。
&&&&&&&&&activity&android:name="com.x210.intentfilters.OneActivity"&android:label="oneActivity"&&&&
&&&&&&&&&&&&&intent-filter&
&&&&&&&&&&&&&&&&&&action&android:name="myapp.action.test1"&/&
&&&&&&&&&&&&&&&&&&action&android:name="myapp.action.test2"&/&
&&&&&&&&&&&&&&&&&&action&android:name="myapp.action.test3"&/&
&&&&&&&&&&&&&&&&&category&android:name="android.intent.category.DEFAULT"&/&&&
&&&&&&&&&&&&&/intent-filter&
&&&&&&&&&/activity&&&span&style="color:#ff0000"&
以下几种Intent请求都可以通过上述&intent-filter&的动作测试。
Intent&intent&=&new&Intent("myapp.action.test1");
startActivity(intent);
Intent&intent&=&new&Intent("myapp.action.test2");
startActivity(intent);
如果Intent请求或&intent-filter&中没有说明具体的Action类型,那么会出现下面两种情况。
(1) 如果&intent-filter&中没有包含任何Action类型,那么无论什么Intent请求都无法和这条&intent-filter&匹配;(2) 反之,如果Intent请求中没有设定Action类型,那么只要&intent-filter&中包含有Action类型,这个Intent请求就将顺利地通过&intent-filter&的行为测试。
2、类别测试
&&&activity&android:name="com.x210.intentfilters.OtherActivity"&android:label="otherActivity"&&&&
&&&&&&&&&&&&&intent-filter&&&
&&&&&&&&&&&&&&&&&action&android:name="myapp.action.test1"&/&
&&&&&&&&&&&&&&&&&category&android:name="cate1"/&
&&&&&&&&&&&&&&&&&category&android:name="cate2"/&
&&&&&&&&&&&&&&&&&category&android:name="android.intent.category.DEFAULT"&/&&&
&&&&&&&&&&&&&/intent-filter&
&&&&&&&&&/activity&
只有当Intent请求中所有的Category与组件中某一个IntentFilter的&category&完全匹配时,才会让该 Intent请求通过测试,IntentFilter中多余的&category&声明并不会导致匹配失败。一个没有指定任何类别测试的 IntentFilter仅仅只会匹配没有设置类别的Intent请求。
以下三种Intent请求都可以通过上述&intent-filter&的类别测试。
&&&&Intent&intent&=&new&Intent("myapp.action.test1");
&&&&intent.addCategory("cate1");
&&&&startActivity(intent);
&&&&Intent&intent&=&new&Intent("myapp.action.test1");
&&&&intent.addCategory("cate2");
&&&&startActivity(intent);
&&&&&&&&Intent&intent&=&new&Intent("myapp.action.test1");
&&&&&&&&intent.addCategory("cate1");
&&&&&&&&intent.addCategory("cate2");
&&&&&&&&startActivity(intent);
实例部分源码:
AndroidManifest.xml
&?xml&version="1.0"&encoding="utf-8"?&
&manifest&xmlns:android="/apk/res/android"
&&&&package="com.x210.intentfilters"
&&&&android:versionCode="1"
&&&&android:versionName="1.0"&&
&&&&&uses-sdk
&&&&&&&&android:minSdkVersion="9"
&&&&&&&&android:targetSdkVersion="9"&/&
&&&&&application
&&&&&&&&android:allowBackup="true"
&&&&&&&&android:icon="@drawable/ic_launcher"
&&&&&&&&android:label="@string/app_name"
&&&&&&&&android:theme="@style/AppTheme"&&
&&&&&&&&&activity
&&&&&&&&&&&&android:name="com.x210.intentfilters.MainActivity"
&&&&&&&&&&&&android:label="@string/app_name"&&
&&&&&&&&&&&&&intent-filter&
&&&&&&&&&&&&&&&&&action&android:name="android.intent.action.MAIN"&/&
&&&&&&&&&&&&&&&&&category&android:name="android.intent.category.LAUNCHER"&/&
&&&&&&&&&&&&&/intent-filter&
&&&&&&&&&/activity&
&&&&&&&&&activity&android:name="com.x210.intentfilters.OneActivity"&android:label="oneActivity"&&&&
&&&&&&&&&&&&&intent-filter&
&&&&&&&&&&&&&&&&&action&android:name="myapp.action.test1"&/&
&&&&&&&&&&&&&&&&&action&android:name="myapp.action.test2"&/&
&&&&&&&&&&&&&&&&&category&android:name="android.intent.category.DEFAULT"&/&&&
&&&&&&&&&&&&&/intent-filter&
&&&&&&&&&/activity&
&&&&&&&&&activity&android:name="com.x210.intentfilters.OtherActivity"&android:label="otherActivity"&&&&
&&&&&&&&&&&&&intent-filter&&&
&&&&&&&&&&&&&&&&&action&android:name="myapp.action.test1"&/&
&&&&&&&&&&&&&&&&&category&android:name="cate1"/&
&&&&&&&&&&&&&&&&&category&android:name="cate2"/&
&&&&&&&&&&&&&&&&&category&android:name="android.intent.category.DEFAULT"&/&&&
&&&&&&&&&&&&&/intent-filter&
&&&&&&&&&/activity&
&&&&&/application&
&/manifest&
MainActivity.java(核心代码)
protected&void&onCreate(Bundle&savedInstanceState)&{
&&&&&&&&super.onCreate(savedInstanceState);
&&&&&&&&setContentView(R.layout.main);&&&&
&&&&&&&&actionbutton&=&(Button)&findViewById(R.id.ActionButton);
&&&&&&&&categorybutton&=&(Button)&findViewById(R.id.CategoryButton);
&&&&&&&&actionbutton.setOnClickListener(new&View.OnClickListener()&{
&&&&&&&&&&&&@Override
&&&&&&&&&&&&public&void&onClick(View&v)&{
&&&&&&&&&&&&&&&&Intent&intent&=&new&Intent("myapp.action.test1");
&&&&&&&&&&&&&&&&startActivity(intent);
&&&&&&&&&&&&}
&&&&&&&&});
&&&&&&&&categorybutton.setOnClickListener(new&View.OnClickListener()&{&&&&&&&&
&&&&&&&&&&&&@Override
&&&&&&&&&&&&public&void&onClick(View&v)&{
&&&&&&&&&&&&&&&&Intent&intent&=&new&Intent("myapp.action.test1");
&&&&&&&&&&&&&&&&intent.addCategory("cate1");
&&&&&&&&&&&&&&&&intent.addCategory("cate2");
&&&&&&&&&&&&&&&&startActivity(intent);
&&&&&&&&&&&&}
&&&&&&&&});
更多开发者职位上
1)">1)">1" ng-class="{current:{{currentPage==page}}}" ng-repeat="page in pages"><li class='page' ng-if="(endIndex<li class='page next' ng-if="(currentPage
相关文章阅读怎么在android实现通过浏览器点击链接打开apk_百度知道
怎么在android实现通过浏览器点击链接打开apk
我有更好的答案
  为了实现这个功能可折腾了我好久,先上一份代码,经楼主验证是绝对可以用的而且也比较清晰的代码!(ps:还是先剧透下吧,第三方大部分浏览器无法成功。)
  点击浏览器中的URL链接,启动特定的App。
  首先做成HTML的页面,页面内容格式如下:
  &a href=&[scheme]://[host]/[path]?[query]&&启动应用程序&/a&
  这一句就可以了。
  各个项目含义如下所示:
  scheme:判别启动的App。 ※详细后述
  host:适当记述
  path:传值时必须的key
※没有也可以
  query:获取值的Key和Value
※没有也可以
  作为测试好好写了一下,如下:
  &a href=&myapp://jp.app/openwith?name=zhangsan&age=26&&启动应用程序&/a&
  接下来是Android端。
  首先在Androi...
其他类似问题
为您推荐:
android的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁如何在android开发使用ACTION_百度知道
如何在android开发使用ACTION
方法如下:前面有用使用Intent来控制& Service使用的参数是Service的类Service的启动/关闭还有另外一种方式来控制通过Intent传入Action的参数在manifest中注册一个Service并且设置一个action&service&&&&&&&&&&&&&&&&&&&android:enabled=&true&&&&&&&&&&&&&&&&android:exported=&false&&&&&&&&&&&&&&&android:name=&com.services.sev.PlayService&&&&&&&&&&&&&&&&&&intent-filter&&&&&&&&&&&&&&&&&&&&action&android:name=&com.example.codetest_1.action.startPlayService&&/&&&&&&&&&&&&&&&&/intent-filter&&&&&&&&&&&&/service&&&注意这个name的字符串可以在Service类中增加一个字段public&static&final&String&ACTION&=&&com.example.codetest_1.action.startPlayService&; &这样 只需修改Intent的调用方法 就可以启动/关闭Service了Intent&intent&=&new&Intent();&&&&&&&&&&&&&&intent.setAction(PlayService.ACTION);&&&&&&&&&&&&&&this.startService(intent); &Intent&intent&=&new&Intent();&&&&&&&&&&&&&&intent.setAction(PlayService.ACTION);&&&&&&&&&&&&&&this.stopService(intent); &
其他类似问题
为您推荐:
提问者采纳
shareI;ic_launcher&Intent shareIntent = new Intent();Intent sharingIntent = new Intent(sharingIntent.getString(R;&shareI&quot, imageUri).setAction(IshareIsendingstartActivity(intent); + getPackageName()+ &send& + &sharingI
imageUri = Uri:/&#47.content.jpeg&&#47, getResources();*/startActivity(Intent.setType(&quot, shareBody).Intent, &
intent = new Intent(Iimage&#47.putExtra(android.addFlags(Intent.parse(&quot.parse(&quot, imageUri).EXTRA_TEXT;private ISubject Here&image/&#47.ACTION_SEND)可以自定义一个ActionBar导航栏的;&#47.ACTION_SEND););Hello&Uri imageUri = Uri.resource.&drawable&#47.share_using))), &quot.putExtra(I):123456
String shareBody = &quot.setType(&startActivity(I/Here is the share content body&text/&#47.FLAG_GRANT_READ_URI_PERMISSION).drawable/ + &plain&textintent, &android.setType(&quot.ACTION_SEND);ic_launcher&/&#47, &sharingIntent.putExtra(Intent.createChooser(sharingI).putExtra(Itype of things);Hello&*&quot.putExtra(android.EXTRA_STREAM;).IshareI);&quot.EXTRA_SUBJECT.createChooser(shareI)).I);/所以你的全部代码(图片+文本)需要变成123456789101112131415161718192021222324
private Uri imageUri.EXTRA_TEXT;&#47.EXTRA_STREAM;/ + getPackageName()+ &quot.string:&#47.putExtra(I).EXTRA_TEXT。其实就相当于不用系统的ActionBar就像是自己定义的titlebar一样 你可以共享下面的代码;shareIntent
来自团队:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁在Android的隐式调用中,如果没有设置action只设置了Category就报ActivityNotFoundEDEVGuide不是说如果Action,Category,Data通过测试就可以了吗,而且Intent的action也可以为空On the other hand, an Intent object that doesn't specify an action automatically passes the test — as long as the filter contains at least one action.
出错代码如下:(ActivityNotFoundException)
Intent intent = new Intent();
//intent.setAction("testAction");//该行如果放开注释就正确
intent.addCategory("testCategory");//如果只设置action不添加category也正确
startActivity(intent);
AndroidManifest.xml
&activity android:name=".Test2"&
&intent-filter&
&action android:name="testAction"&&/action&
&category android:name="testCategory"&&/category&
&category android:name="android.intent.category.DEFAULT"&&/category&
&/intent-filter&
&/activity&
问题补充:&div class="quote_title"&liveHappy 写道&/div&&div class="quote_div"&呵呵 又是你啊
&br /&
&br /&&div class="quote_title"&引用&/div&&div class="quote_div"&On the other hand, an Intent object that doesn't specify an action automatically passes the test — as long as the filter contains at least one action.&/div&
&br /&这句话的意思,从另一方面说,一个没有指定一个action的Intent对象自动通过测试,但至少该fifer有一个action.
&br /&说白了,就是fifer不指定action的指向,也得把action写上。
&br /&能明白不?
&br /&而且要是自己定义的action 就必须指定action。&/div&
&br /&
&br /&而且要是自己定义的action 就必须指定action?
&br /&意思是不是如果IntentFilter中自定义了action类型那么Intent中就一定要也设置了这个action类型才能通过测试?
&br /&
&br /&
问题补充:&div class="quote_title"&liveHappy 写道&/div&&div class="quote_div"&嗯 对头。
&br /&在你的xml中,一个Activity的IntentFilter中定义了Action
&br /&那么这个Intent也包含了相同的action,那就与这个目标Action匹配。&/div&
&br /&
&br /&呵呵,还是有点不理解。
&br /&按照On the other hand, an Intent object that doesn't specify an action automatically passes the test — as long as the filter contains at least one action.描述的。
&br /&我的Intent没有设置action,而我的
&br /& &intent-filter&&
&br /&&&&&&&&&&&&&&&& &action android:name="testAction"&&/action&&
&br /&&&&&&&&&&&&&&&& &category android:name="testCategory"&&/category&&
&br /&&&&&&&&&&&&&&&& &category android:name="android.intent.category.DEFAULT"&&/category&&
&br /&&/intent-filter&
&br /&IntentFilter中设置有一个action,那他就应该通过这个Filter的测试呀!
&br /&
&br /&
问题补充:&div class="quote_title"&liveHappy 写道&/div&&div class="quote_div"&你的理解也对。
&br /&&div class="quote_title"&引用&/div&&div class="quote_div"&as long as the filter contains at least one action&/div&
&br /&如果Intent不指定action 至少在fiter中有一个action。那它没有说需要其他别的,可能就是这样:
&br /&&intent-filter&&
&br /&&&&&&&&&&&&&&&& &action android:name="testAction"&&/action&&
&br /&&/intent-filter&
&br /&不确定。
&br /&
&br /&要是intent指定了, 就要和fiter中的相同才能匹配。
&br /&你试试上面的,把其他的去掉。&/div&
&br /&
&br /&
&br /&呵呵,其他的去掉就不能通过category测试了!
&br /&关键是为什么不指定action就不能通过测试了,这和DevGuide描述的不一样呀?
&br /&而在 menu.addIntentOptions中如果Intent中没有设置action也是可以匹配到IntentFilter的
&br /&
采纳的答案
我想不会错的。
他都说了,只要过滤器包含至少一个动作,intent没有指定动作也会自动通过这个测试。
既然说了,那只能是可行的。可能还是哪写的不对呗。
你的理解也对。
引用as long as the filter contains at least one action
如果Intent不指定action 至少在fiter中有一个action。那它没有说需要其他别的,可能就是这样:
&intent-filter&&
&&&&&&&&&&&&&&& &action android:name="testAction"&&/action&&
&/intent-filter&
要是intent指定了, 就要和fiter中的相同才能匹配。
你试试上面的,把其他的去掉。
嗯 对头。
在你的xml中,一个Activity的IntentFilter中定义了Action
那么这个Intent也包含了相同的action,那就与这个目标Action匹配。
Intent中的category属性是一个执行Action的附加信息,必须要有一个Action的。Intent的使用详细信息可以参考
呵呵 又是你啊
引用On the other hand, an Intent object that doesn't specify an action automatically passes the test — as long as the filter contains at least one action.
这句话的意思,从另一方面说,一个没有指定一个action的Intent对象自动通过测试,但至少该fifer有一个action.
说白了,就是fifer不指定action的指向,也得把action写上。
能明白不?
而且要是自己定义的action 就必须指定action。
已解决问题
未解决问题}

我要回帖

更多关于 thinkphp lt gt 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信