ContentProvider介绍
ContentProvider"内容提供者"实现步骤
ContentProvider组成部分
ContentProvider(内容提供者)的scheme已经由Android所规定.
scheme为:content://
2.主机名
主机名(或叫Authority)用于唯一标识这个ContentProvider,比如这里 com.contentproviderdb.TestContentProvider,外部调用者可以 根据这个标识来找到它。
3.path
上面三个部分是主要的,还可以有更详细的,比如还包含数据id /User/id。
如果要把一个字符串转换成Uri,可以使用Uri类中的parse()方法,如下:
然后再介绍一下UriMatcher类使用:
因为Uri代表了要操作的数据,所以我们经常需要解析Uri,并从Uri中获取数据。Android系统提供了两个用于操作Uri 的工具类,分别为UriMatcher和ContentUris 。掌握它们的使用,会便于我们的开发工作。
UriMatcher类用于匹配Uri,它的用法如下:
if(uriMatcher.match(uri) == USER)
首先第一步把你需要匹配Uri路径全部给注册上,如下:
uriMatcher.addURI("com.contentproviderdb.TestContentProviderr","User",USER);
注册完需要匹配的Uri后,就可以使用sMatcher.match(uri)方法对输入的Uri进行匹配,如果匹配就返回匹配码,匹配 码是调用addURI()方法传入的第三个参数。
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499949520
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499928767
https://buluo.qq.com/p/detail.html?bid=92799&pid=7168867-1503839527
https://buluo.qq.com/p/detail.html?bid=92799&pid=7168867-1503839527
https://buluo.qq.com/p/detail.html?bid=92799&pid=7168867-1503839513
https://buluo.qq.com/p/detail.html?bid=92799&pid=7168867-1503838541
https://buluo.qq.com/p/detail.html?bid=92799&pid=7168867-1503838527
https://buluo.qq.com/p/detail.html?bid=92799&pid=7168867-1503834821
https://buluo.qq.com/p/detail.html?bid=92799&pid=7168867-1503834799
https://buluo.qq.com/p/detail.html?bid=92799&pid=7168867-1503832624
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499949550
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499949536
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499949520
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499949506
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499949491
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499945867
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499945852
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499937902
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499937890
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499936990
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499936972
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499936955
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499936942
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499928754
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499928735
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499928383
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499928368
https://buluo.qq.com/p/detail.html?bid=92799&pid=4685111-1499928350