Android匹配Uri工具类UriMatcher
来源:互联网 发布:python编码汉字互转 编辑:程序博客网 时间:2024/06/02 07:09
转载请标明出处: http://blog.csdn.net/wu_wxc/article/details/51386958
本文出自【吴孝城的CSDN博客】
UriMatcher
用来匹配Content provider的URI
urimatcher主要用于匹配URI
官网:http://developer.android.com/intl/zh-cn/reference/android/content/UriMatcher.html
使用
初始化
private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
常量UriMatcher.NO_MATCH表示不匹配任何路径时的返回码
注册需要的URI
“#”为数据的通配符,“*”为所有文本的通配符,匹配码为第三个参数。
static { sURIMatcher.addURI("cn.wuxiaocheng.people", "name", 1); sURIMatcher.addURI("cn.wuxiaocheng.people", "age/#", 2);}
与已注册的URI进行匹配
public String getType(Uri uri){ int match = sURIMatcher.match(uri); switch(match){ case 1: return "vnd.android.cursor.dir/person"; case 2: return "vnd.android.cursor.item/person"; default: return null; }}
如果.match()方法匹配content://cn.wuxiaocheng.people/name,则返回匹配码为1
如果.match()方法匹配content://cn.wuxiaocheng.people/age/23,则返回匹配码为2
0 0
- Android匹配Uri工具类UriMatcher
- Uri,UriMatcher,ContentUris工具类简单介绍
- 【Android】Uri、UriMatcher、ContentUris详解
- Android Uri、UriMatcher、ContentUris详解
- 【Android】Uri、UriMatcher、ContentUris详解
- 【Android】Uri、UriMatcher、ContentUris详解
- 【Android】Uri、UriMatcher、ContentUris详解
- 【Android】Uri、UriMatcher、ContentUris详解
- 【Android】Uri、UriMatcher、ContentUris详解
- 【Android】Uri、UriMatcher、Cont…
- 【Android】Uri、UriMatcher、ContentUris详解
- 【Android】Uri、UriMatcher、ContentUris详解
- [Android]Uri、UriMatcher、ContentUris详解
- Android:Uri、UriMatcher、ContentUris详解
- [Android]Uri、UriMatcher、ContentUris详解
- 【Android】Uri、UriMatcher、ContentUris详解
- Android Uri、UriMatcher、ContentUris详解
- 【Android】Uri、UriMatcher、ContentUris详解
- 添加LogCat 至 eclipse --2
- 加密
- 图片跟随鼠标移动(jquery)
- OpenGl 学习笔记 01
- AndroidStudio--Terminal的使用
- Android匹配Uri工具类UriMatcher
- html初探
- hdu-2489 Minimal Ratio Tree(DFS+最小生成树)
- 学习OpenCV——Surf(特征点篇)&flann快速最近邻搜索算法
- Partition-方案一. 通过 Export/import 方法
- django 购物系统 - 添加至购物车表单
- eclipse/intellij idea 远程调试hadoop 2.6.0
- android获取屏幕的宽高
- AFNetworking 3.0迁移指南