在实现
ContentProvider时,在文档中定义所有uris有明显的推荐.但是我对URI匹配器部分感到困惑:例如,我有包org.company.example,表名为“items”,然后定义
public static final Uri CONTENT_URI = Uri.parse("content://org.company.example.sampleprovider/items");
我应该使用什么权限部分来匹配静态init中的URI:
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); }
解决方法
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); }