UriMatcher类使用介绍
来源:互联网 发布:seo学徒招聘 编辑:程序博客网 时间:2024/05/19 21:42
因为Uri代表了要操作的数据,所以我们经常需要解析Uri,并从Uri中获取数据。Android系统提供了两个用于操作Uri的工具类,分别为UriMatcher 和ContentUris 。掌握它们的使用,会便于我们的开发工作。
UriMatcher类用于匹配Uri,它的用法如下:
首先第一步把你需要匹配Uri路径全部给注册上,如下:
//常量UriMatcher.NO_MATCH表示不匹配任何路径的返回码UriMatcher sMatcher = new UriMatcher(UriMatcher.NO_MATCH);//如果match()方法匹配content://cn.itcast.provider.personprovider/person路径,返回匹配码为1sMatcher.addURI(“cn.itcast.provider.personprovider”, “person”, 1);//添加需要匹配uri,如果匹配就会返回匹配码//如果match()方法匹配content://cn.itcast.provider.personprovider/person/230路径,返回匹配码为2sMatcher.addURI(“cn.itcast.provider.personprovider”, “person/#”, 2);//#号为通配符switch (sMatcher.match(Uri.parse("content://cn.itcast.provider.personprovider/person/10"))) { case 1 break; case 2 break; default://不匹配 break;}
注册完需要匹配的Uri后,就可以使用sMatcher.match(uri)方法对输入的Uri进行匹配,如果匹配就返回匹配码,匹配码是调用addURI()方法传入的第三个参数,假设匹配content://cn.itcast.provider.personprovider/person路径,返回的匹配码为1
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍[转]
- UriMatcher类和ContentUris类使用介绍
- android下UriMatcher类使用介绍
- UriMatcher类使用介绍/ ContentUris类使用介绍
- 我的android 第23天 - UriMatcher类使用介绍
- Uri、UriMatcher、ContentUris类介绍
- Uri,UriMatcher,ContentUris工具类简单介绍
- Android学习笔记---20_采用ContentProvider对外共享数据, UriMatcher类使用介绍 ,ContentUris类使用介绍,使用ContentResolver操作Conte
- 2204 let's play dota.
- W3C DOM之scrollIntoView的用法
- GCC安装与编译
- C#|WINCE按钮重绘
- 杂谈2
- UriMatcher类使用介绍
- 设置MYSQL允许用IP访问
- Windows2008R2新添加的硬盘无法识别 VM虚拟机
- Linux_利用fdisk建立swap分区
- nsswitch.conf文件详解
- ADO.NET Entity Framework 深入分析, Part 4 (提供示例程序下载)
- 数据库查询优化原则
- JAVA 方法的重写和重载
- CENTOS的GIT安装及使用