android Intent匹配,自定义action data category

原创 2013年12月05日 13:14:14


public Intent setAction (String action)

Added in API level 1
Set the general action to be performed.

action	An action name, such as ACTION_VIEW. Application-specific actions should be prefixed with the vendor's package name.
Returns the same Intent object, for chaining multiple calls into a single statement.

public Intent setData (Uri data)

Added in API level 1
Set the data this intent is operating on. This method automatically clears any type that was previously set by setType(String) or setTypeAndNormalize(String).

Note: scheme matching in the Android framework is case-sensitive, unlike the formal RFC. As a result, you should always write your Uri with a lower case scheme, or use normalizeScheme() or setDataAndNormalize(Uri) to ensure that the scheme is converted to lower case.

data	The Uri of the data this intent is now targeting.
Returns the same Intent object, for chaining multiple calls into a single statement.

public Intent addCategory (String category)

Added in API level 1
Add a new category to the intent. Categories provide additional detail about the action the intent performs. When resolving an intent, only activities that provide all of the requested categories will be used.

category	The desired category. This can be either one of the predefined Intent categories, or a custom category in your own namespace.
Returns the same Intent object, for chaining multiple calls into a single statement.

可以看出action, data, category都是可以自定义的。

Only three aspects of an Intent object are consulted when the object is tested against an intent filter:

data (both URI and data type) 

The extras and flags play no part in resolving which component receives an intent.



You can also define your own action strings for activating the components in your application. Those you invent should include the application package as a prefix — for example: "com.example.project.SHOW_COLOR".


In principle, therefore, an Intent object with no categories should always pass this test, regardless of what's in the filter.
 That's mostly true. However, with one exception, Android treats all implicit intents passed to startActivity() 
as if they contained at least one category: "android.intent.category.DEFAULT" (the CATEGORY_DEFAULT constant). 
Therefore, activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" 
in their intent filters. (Filters with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" settings are the exception. 
They mark activities that begin new tasks and that are represented on the launcher screen.
 They can include "android.intent.category.DEFAULT" in the list of categories, but don't need to.) 

Intent 匹配规则

本文翻译自Android API Guide,并经过整理. Intent 匹配规则:做三项测试:action,data,category 1.action测试: 一个过滤器中可...
  • crazyman2010
  • crazyman2010
  • 2014年12月17日 10:09
  • 1408


1 前言Intent作为联系各Activity之间的纽带,其作用并不仅仅只限于简单的数据传递。通过其自带的属性,其实可以方便的完成很多较为复杂的操作。例如直接调用拨号功能、直接自动调用合适的程序打开不...
  • mffandxx
  • mffandxx
  • 2017年01月03日 15:00
  • 681


Android隐式启动Activity匹配详解:Action,category,data 分类:技术 | 标签: Android   2012-08-08 15:44阅读(4789)评论(...
  • yushengabc
  • yushengabc
  • 2015年12月21日 11:41
  • 2420

Pro Android学习笔记(十二):了解Intent(下)

解析Intent,寻找匹配Activity 如果给出component名字(包名、类名)是explicit intent,否则是implicit intent。对于explicit intent,关键...
  • flowingflying
  • flowingflying
  • 2013年07月19日 17:52
  • 10919


一、为什么要用Monkey 测试?   简单在说就是象猴子一样乱点,为了测试软件的稳定性,健壮性。号称最快速有效的方法。有时候运行相同系列的测试,即使是复杂的测试,但是以相同的顺序和路径,即使一遍又一...
  • automationwei
  • automationwei
  • 2015年08月26日 19:19
  • 861


Component属性 代码示例public class MainActivity extends Activity{ @Override protected void onCr...
  • u010321471
  • u010321471
  • 2015年06月26日 22:42
  • 1142


收集学习一下android.intent.action的使用: 1.从google搜索内容  Intent intent = new Intent();  intent.setAction(...
  • u014031072
  • u014031072
  • 2017年04月13日 18:26
  • 1066

Android Intent隐式启动通过scheme打开应用 http://www.jianshu...
  • u011904605
  • u011904605
  • 2016年12月06日 02:34
  • 3121


从任意app,启动另外一个app的activity: 1.  Intent i = new Intent();           ComponentName cn = new Compo...
  • Only_Tan
  • Only_Tan
  • 2014年03月17日 10:25
  • 2104


Intent中的四个重要属性——Action、Data、Category、Extras   Intent作为联系各Activity之间的纽带,其作用并不仅仅只限于简单的数据传递。...
  • zs2538596
  • zs2538596
  • 2014年08月30日 11:32
  • 417
您举报文章:android Intent匹配,自定义action data category