您的位置:首页 > 其它

内容提供

2015-06-08 23:08 162 查看
调用内容提供 提供者不用启动

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)中设置

是向提供者判断采用那种方法的钥匙 是提供者事先规定好的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: