android – 内容提供者URI匹配器

前端之家收集整理的这篇文章主要介绍了android – 内容提供者URI匹配器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在实现 ContentProvider时,在文档中定义所有uris有明显的推荐.但是我对URI匹配器部分感到困惑:例如,我有包org.company.example,表名为“items”,然后定义 @H_403_2@public static final Uri CONTENT_URI = Uri.parse("content://org.company.example.sampleprovider/items");

我应该使用什么权限部分来匹配静态init中的URI:

@H_403_2@private static final UriMatcher uriMatcher; static { uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher.addURI("what goes here?","items",ITEM); uriMatcher.addURI("what goes here?","items/#",ITEM_ID); }

解决方法

@H_403_2@public static final String PROVIDER_NAME = "org.company.example.sampleprovider"; public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME); private static final UriMatcher uriMatcher; static { uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher.addURI(PROVIDER_NAME,ITEM); uriMatcher.addURI(PROVIDER_NAME,ITEM_ID); }

猜你在找的Android相关文章