调用内容提供 提供者不用启动
1 继承ContentProvider
重写方法
2 在onCreate中匹配器注册uri格式的权限
UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
内容使用者
1 创建连接解析器
ContentResolver r = this.getContentResolver();
2 把字符串解析成uri
Uri uri=Uri.parse("content://com.tarena.provider.WORD/x");
content://com.tarena.provider.WORD/words/9
结尾的words只是传入了选择方法钥匙
3 使用r+uri调用内容提供器的方法
r.query(uri,...)
r.delete(uri,...)
传入的uri:content://com.tarena.provider.WORD/words/9
long id = ContentUris.parseId(uri);解析出的是 9
是使用内容者向提供者提供的参数
int code = matcher.match(uri);解析出的是 words所代表的 1
在matcher.addURI("com.tarena.provider.WORD", "words/#", 1)中设置
是向提供者判断采用那种方法的钥匙 是提供者事先规定好的
1 继承ContentProvider
重写方法
2 在onCreate中匹配器注册uri格式的权限
UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
内容使用者
1 创建连接解析器
ContentResolver r = this.getContentResolver();
2 把字符串解析成uri
Uri uri=Uri.parse("content://com.tarena.provider.WORD/x");
content://com.tarena.provider.WORD/words/9
结尾的words只是传入了选择方法钥匙
3 使用r+uri调用内容提供器的方法
r.query(uri,...)
r.delete(uri,...)
传入的uri:content://com.tarena.provider.WORD/words/9
long id = ContentUris.parseId(uri);解析出的是 9
是使用内容者向提供者提供的参数
int code = matcher.match(uri);解析出的是 words所代表的 1
在matcher.addURI("com.tarena.provider.WORD", "words/#", 1)中设置
是向提供者判断采用那种方法的钥匙 是提供者事先规定好的