IntentFilter
简述:结构化描述intent匹配的信息。包含:action,categories and data(via type,scheme ,path),还有priority, to order multiple matching filters.
IntentFilter 中如果action为空,则视为通配符,如果type为空,则intent必须不设type,否则匹配不上。
data被分为3个属性:type,scheme,authority/path 任何设置的属性intent必须匹配上。
设置了scheme 而没设type,则intent也必须类似,不能设置type,也不能是content: URI.
设置了type而没设scheme:将匹配上没有URI的intent,或者content:,file:的uri。
设置了authority:必须指定一个或多个相关联的schemes
设置了path:唏嘘指定一个或多个相关联的schemes
匹配规则:
IntentFilter 匹配Intent的上的条件:
Action : 值相同 ,或则IntentFilter未指定action.
DataType:. 系统通过调用Intent.resolve(ContentResolver)获取type,通配符*
在Intent/IntentFilter的MIME type中使用,区分大小写
DataScheme:系统通过调用Intent. getData() and Uri.getScheme())获取scheme, 区分大小写
DataAuthority:必须有一个dataScheme匹配上且authority值匹配上,或者IntentFilter没有定义。Intent. getData() and Uri.getAuthority()获取authority.
DataPath: scheme and authority必须先匹配上 ntent. getData() and Uri.getPath(),获取. 或者IntentFilter没有定义
Categories:all of the categories in the Intent match categories given in the filter 多余的Categorie,不影响intent匹配,如果IntentFilter
没有指定Categorie,则只能匹配上没有Categorie的intent。
常用intent列表:
Android Intent 用法汇总
显示网页
- <activity android:name="BrowserActivity" android:label="Browser" android:launchMode="singleTask" android:alwaysRetainTaskState="true" android:configChanges="orientation|keyboardHidden" android:theme="@style/BrowserTheme">
- <!--
For these schemes were not particular MIME type has been
supplied, we are a good candidate.
-->
- <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:scheme="https" />
<data android:scheme="about" />
</intent-filter>
- <!--
For these schemes where any of these particular MIME types
have been supplied, we are a good candidate.
-->
- <intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:mimeType="text/html" />
<data android:mimeType="text/plain" />
<data android:mimeType="application/xhtml+xml" />
<data android:mimeType="application/vnd.wap.xhtml+xml" />
</intent-filter>
- <!--
We are also the main entry point of the browser.
-->
- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
- <intent-filter>
<action android:name="android.intent.action.WEB_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
- <intent-filter>
<action android:name="android.intent.action.WEB_SEARCH" />
<action android:name="android.intent.action.MEDIA_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
- <intent-filter>
<action android:name="android.net.http.NETWORK_STATE" />
<action android:name="android.intent.action.PROXY_CHANGE" />
</intent-filter>
</activity>
1. Uri uri = Uri.parse("http://google.com");
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
显示地图
1. Uri uri = Uri.parse("geo:38.899533,-77.036476");
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
4. //其他 geo URI 範例
5. //geo:latitude,longitude
6. //geo:latitude,longitude?z=zoom
7. //geo:0,0?q=my+street+address
8. //geo:0,0?q=business+near+city
9. //google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom
路径规划
1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
4. //where startLat, startLng, endLat, endLng are a long with 6 decimals like: 50.123456
打电话
1. //叫出拨号程序
2. Uri uri = Uri.parse("tel:0800000123");
3. Intent it = new Intent(Intent.ACTION_DIAL, uri);
4. startActivity(it);
1. //直接打电话出去
2. Uri uri = Uri.parse("tel:0800000123");
3. Intent it = new Intent(Intent.ACTION_CALL, uri);
4. startActivity(it);
5. //用這個,要在 AndroidManifest.xml 中,加上
6. //<uses-permission id="android.permission.CALL_PHONE" />
传送SMS/MMS
1. //调用短信程序
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. it.putExtra("sms_body", "The SMS text");
4. it.setType("vnd.android-dir/mms-sms");
5. startActivity(it);
1. //传送消息
2. Uri uri = Uri.parse("smsto://0800000123");
3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
4. it.putExtra("sms_body", "The SMS text");
5. startActivity(it);
1. //传送 MMS
2. Uri uri = Uri.parse("content://media/external/images/media/23");
3. Intent it = new Intent(Intent.ACTION_SEND);
4. it.putExtra("sms_body", "some text");
5. it.putExtra(Intent.EXTRA_STREAM, uri);
6. it.setType("image/png");
7. startActivity(it);
传送 Email
1. Uri uri = Uri.parse("mailto:xxx@abc.com");
2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
3. startActivity(it);
1. Intent it = new Intent(Intent.ACTION_SEND);
2. it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");
3. it.putExtra(Intent.EXTRA_TEXT, "The email body text");
4. it.setType("text/plain");
5. startActivity(Intent.createChooser(it, "Choose Email Client"));
1. Intent it=new Intent(Intent.ACTION_SEND);
2. String[] tos={"me@abc.com"};
3. String[] ccs={"you@abc.com"};
4. it.putExtra(Intent.EXTRA_EMAIL, tos);
5. it.putExtra(Intent.EXTRA_CC, ccs);
6. it.putExtra(Intent.EXTRA_TEXT, "The email body text");
7. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
8. it.setType("message/rfc822");
9. startActivity(Intent.createChooser(it, "Choose Email Client"));
1. //传送附件
2. Intent it = new Intent(Intent.ACTION_SEND);
3. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
4. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
5. sendIntent.setType("audio/mp3");
6. startActivity(Intent.createChooser(it, "Choose Email Client"));
播放多媒体
Uri uri = Uri.parse("file:///sdcard/song.mp3");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
it.setType("audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
Market 相关
1. //寻找某个应用
2. Uri uri = Uri.parse("market://search?q=pname:pkg_name");
3. Intent it = new Intent(Intent.ACTION_VIEW, uri);
4. startActivity(it);
5. //where pkg_name is the full package path for an application
1. //显示某个应用的相关信息
2. Uri uri = Uri.parse("market://details?id=app_id");
3. Intent it = new Intent(Intent.ACTION_VIEW, uri);
4. startActivity(it);
5. //where app_id is the application ID, find the ID
6. //by clicking on your application on Market home
7. //page, and notice the ID from the address bar
Uninstall 应用程序
1. Uri uri = Uri.fromParts("package", strPackageName, null);
2. Intent it = new Intent(Intent.ACTION_DELETE, uri);
3. startActivity(it);
分享到:
相关推荐
4.5.1 Intent及IntentFilter介绍 4.5.2 Activity信息的管理 4.5.3 Intent 匹配查询分析 4.5.4 queryIntentActivities总结 4.6 installd及UserManager介绍 4.6.1 installd介绍 4.6.2 UserManager介绍 4.7 本...
- **Intent及IntentFilter介绍**:解释了Intent和IntentFilter的概念及其在Android系统中的作用。 - **Activity信息的管理**:说明了PackageManagerService如何管理和维护Activity的信息。 - **Intent匹配查询...
下面将详细介绍IntentFilter的各个组成部分及其工作原理。 首先,我们要理解Intent的基本概念。Intent分为显式Intent和隐式Intent。显式Intent会明确指定要启动的目标组件,而隐式Intent则不指定,而是通过设置...
下面将详细介绍这四个组件及其主要功能。 1. Activity:Activity 是用户与应用程序交互的主要接口,代表了一个可视化的用户界面。每个 Activity 都是一个单独的屏幕,可以包含各种 UI 控件,并能响应用户的事件。...
IntentFilter用于描述Activity或BroadcastReceiver能处理的Intent类型,这样系统就能根据Intent的属性找到合适的组件来执行任务。例如,一个用于查看联系人的Activity会在AndroidManifest.xml中定义一个IntentFilter...
例如,一个 IntentFilter 可以声明 Activity 能处理 VIEW 动作和特定类型的 URI,使得系统能够根据 Intent 找到合适的 Activity 启动。当启动 Activity 时,系统会遍历 IntentFilter,选择最佳匹配的 Activity。 2....
IntentFilter用于描述Activity能处理的Intent类型,定义在AndroidManifest.xml中,使得系统可以根据Intent自动启动相应的Activity。这种机制实现了组件之间的解耦合,Activity可以被其他组件重复利用,并且可以随时...
IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("com.example.MY_ACTION"); BroadcastReceiver myReceiver = new MyBroadcastReceiver(); registerReceiver(myReceiver, intentFilter); `...
以下将详细介绍如何在Android中实现这个功能。 首先,我们需要了解Android的短信管理权限。在AndroidManifest.xml文件中,必须添加以下权限: ```xml ``` `SEND_SMS`权限用于发送短信,`READ_SMS`则用于读取短信...
**Android基础应用介绍** 在移动开发领域,Android操作系统占据着重要的地位,它是Google主导的开源项目,为开发者提供了丰富的API和工具,使得开发者能够构建出各种各样的应用程序。本PPT将带你走进Android基础...
我们将基于这些信息,详细介绍Android广播接收器的相关知识。 首先,广播接收器是Android应用与系统和其他应用之间通信的一种方式。系统会发送广播Intent,广播接收器通过注册来监听特定的Intent动作,当匹配的广播...
下面将详细介绍极光推送Android SDK的使用及其在Android Studio中的集成步骤。 **极光推送核心概念与功能** 1. **推送消息类型**:极光推送支持通知消息和自定义消息两种类型。通知消息是系统级别的,会在状态栏...
本文档详细介绍了几种实现Android页面跳转的方法,并通过实例代码进行了具体演示。 #### 第一种方式:使用Action跳转 ##### Action概念解析 - **Action**:在Android中,`Intent`用来描述应用组件间的一种请求或...
综上所述,这份资料详细介绍了安卓系统中广播信息的运行机制,包括广播的创建、注册、接收以及如何处理系统和自定义广播,同时也涵盖了权限控制、广播类型、优化策略等多个方面,对理解并实践Android中的广播通信有...
在那个程序中使用的是intentFilter这个类,然后在activity中使用registerReceiver函数来发送广播信息,这些代码的实现都是在java语句中实现。这是第一种注册广播消息的方法,另外一种方法是在AndroidMainifest.xml...
IntentFilter dataConnectionFilter = new IntentFilter(Intent.ACTION_DATA_CONNECTION_STATE_CHANGED); registerReceiver(dataConnectionReceiver, dataConnectionFilter); ``` #### 15. DATE_CHANGED_ACTION ...
4. **Intent和IntentFilter**:讲解Intent的作用,如何使用Intent在组件间传递数据,以及如何通过IntentFilter响应用户操作和系统广播。 5. **UI设计**:包括XML布局文件的编写,视图控件的使用(如TextView、...
Android 系统中提供了多种方式来获取电池电量,本文将详细介绍如何通过 BroadcastReceiver 获取电池电量信息。 一、Android 中的电池电量获取方式 Android 系统中提供了多种方式来获取电池电量,常用的方式有: 1...