ContentProvider内容介绍(1)

来源:互联网 发布:应届生求职网站知乎 编辑:程序博客网 时间:2024/05/23 18:33

       1, 创建类,继承ContentProvider抽象类


            boolean onCreate()
            Cursor query(Uri,String[],String,String [],String)
            Uri insert(Uri,ContentValues)
            int update(Uri,ContentValues,String,String[])
            int delete(Uri,String,String[])
            String getType(Uri)
        定义公共的Authority和Code的访问字段
        定义UriMatcher,并增加相应的操作类型
        在相应的方法中使用UriMatcher.match(Uri)方法获取操作类型
        在AndroidManifest.xml清单中注册ContentProvider
            使用<permission>标签声明权限
            使用<provider>标签注册ContentProvider,并声明相关的属性

        注意:path的路径中不能加"/"前辍


   2, ContentResolver使用方法


        通过Context.getContentResolver()调用相关方法
            query(Uri,String[],String,String [],String)
            insert(Uri,ContentValues)
            update(Uri,ContentValues,String,String[])
            delete(Uri,String,String[])
            getType(Uri)

        在AndroidManifest.xml清单中声明ContentProvider要求的权限


  3, 截取Uri地址和拼接Uri地址


        Uri对象的截取方法
            public abstract String getLastPathSegment() 获取最一个“/”后的内容
            public abstract String getPath () 获取path部分
            public abstract List<String> getPathSegments () 获取path中的每一个"/"后的内容
        Uri对象的拼接方法
            public static Uri withAppendedPath(Uri baseUri, String pathSegment)
        ContentUris对象的截取id的方法
            public static long parseId (Uri contentUri)
        ContentUris对象的拼接id的方法
            public static Uri withAppendedId (Uri contentUri, long id)
0 0
原创粉丝点击