android content provider

Uri类

Uri uri = Uri.parse("content://com.example.provider.contactprovider/contact/11")

UriMatcher 识别URi

  1. UriMatcher uriMatcher=new UriMatcher(UriMatcher.NO_MATCH);

    匹配失败时返回UriMatcher.NO_MATCH

  2. 注册 uriMatcher.addURI("com.example.app.provider", "table1", number);

    权限(android:authorities) "com.example.app.provider"
    路径 "table1" ,"table1/#" ,"table1/*"
    匹配码 number

  3. 使用 uriMatcher.match(uri) 返回匹配码
  4. 通配符

    *:表示匹配任意长度的任意字符
    #:表示匹配任意长度的数字

MIME 类型和子类型

读取数据 ContentResolver Content.getContentResolver()

Android附带的ContentProvider

创建自定义的ContentProvider extends ContentProvider

访问权限