UriMatcher使用:
1、初始化
UriMatcher matcher=new UriMatcher(UriMatcher.NO_MATCH);
2、注册需要的uri
matcher.addURI("com.android.jaxen","people",PEOPLE);
3、进行匹配
Uri uri=Uri.parse("content://"+"com.android.jaxen"+"/people");
int match=matcher.match(uri);
switch(match){
case PEOPLE:
return “com.android.jaxen.people";
}
ContentUris使用
ContentUris类用于获取Uri路径后面的ID部分
1:为路径加上ID:withAppendedId(uri,id)
例子:Uri uri=Uri.parse("content://com.yfz.Lesson/people")
Uri newuri=ContentUris.withAppendedId(uri,10);
2:从路径中获取ID:parseId(uri)
Uri uri=Uri.parse("content://com.yfz.Lesson/people/10");
long personid=ContentUris.parseId(uri);
则personid=10