、什么是ContentProviderContentProvider用来存储和检索数据ContentProvider是应用之间互相访问数据的唯一方法Android自身提供了一些常用的Provideraudio、video、image、contacts等如果你想使你的数据能够共享,要么建立一个你自己的ContentProvider;:getContentResolver()使用ContentResolver的方法访问数据库查找:query插入:insert更新:update删除::.(Uriuri,String[]projection,Stringselection,String[]selectionArgs,StringsortOrder)(Uriuri,String[]projection,Stringselection,String[]selectionArgs,StringsortOrder)[]projection=newString[]{,,,};Uricontacts=;CursormanagedCursor=managedQuery(contacts,projection,//Whichcolumnstoreturnnull,//Whichrowstoreturn(allrows)null,//Selectionarguments(none)//+"ASC");.ContentProvider的查找privatevoidgetColumnData(Cursorcur){if(()){Stringname,phoneNumber;intnameColumn=();intphoneColumn=();StringimagePath;do{name=(nameColumn);phoneNumber=(phoneColumn);}while(());}}.修改ContentProvider的数据增加一条新记录:insert给一条已存在的记录增加新信息:insert更新记录:update删除记录:delete借助:ContentValues、=newContentValues();//(,"AbrahamLincoln");//1=thenewcontactisaddedtofavorites//0=(,1);Uriuri=getContentResolver().insert(,values);.已有记录增加新信息UriphoneUri=null;phoneUri=(uri,);();(,
android基础-contentprovider 来自淘豆网www.taodocs.com转载请标明出处.