我的android 第23天 - UriMatcher类使用介绍
来源:互联网 发布:沙城传说翅膀进阶数据 编辑:程序博客网 时间:2024/05/07 20:58
我的android 第23天 - UriMatcher类使用介绍
因为Uri代表了要操作的数据,所以我们经常需要解析Uri,并从Uri中获取数据。Android系统提供了两个用于操作Uri的工具类,分别为UriMatcher 和ContentUris 。掌握它们的使用,会便于我们的开发工作。
UriMatcher类用于匹配Uri,它的用法如下:
首先第一步把你需要匹配Uri路径全部给注册上,如下:
//常量UriMatcher.NO_MATCH表示不匹配任何路径的返回码
UriMatcher sMatcher =newUriMatcher(UriMatcher.NO_MATCH);
//如果match()方法匹配content://cn.itcast.provider.personprovider/person路径,返回匹配码为1
sMatcher.addURI(“cn.itcast.provider.personprovider”,“person”, 1);//添加需要匹配uri,如果匹配就会返回匹配码
//如果match()方法匹配content://cn.itcast.provider.personprovider/person/230路径,返回匹配码为2
sMatcher.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
下载视频代码
- 我的android 第23天 - UriMatcher类使用介绍
- android下UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍
- UriMatcher类使用介绍[转]
- UriMatcher类和ContentUris类使用介绍
- UriMatcher类使用介绍/ ContentUris类使用介绍
- Uri、UriMatcher、ContentUris类介绍
- UriMatcher类的简介
- Android学习笔记---20_采用ContentProvider对外共享数据, UriMatcher类使用介绍 ,ContentUris类使用介绍,使用ContentResolver操作Conte
- 界面化的centos5.5系统 root用户忘记密码解决方案
- 【Android 应用开发】AndroidUI设计之 布局管理器 - 详细解析布局实现
- Clojure 学习入门(17)—— 异常处理
- iOS应用开发最佳实践:编写高质量的Objective-C代码
- sms 短信接收 续
- 我的android 第23天 - UriMatcher类使用介绍
- 一步一步实现五子棋5
- 趣味横生的程序员搞怪代码注释
- Android 调用父类方法,进行子界面刷新
- string_stringBuffer对象
- 近期QQ空间转载的日志有图片显示自己的头像昵称QQ号等
- C#如何获取网页验证码图片
- 写在周一
- 从PyOpenCV到CV2