创建Contentprovider,
创建Contentprovider:
1. 创建一个provider----ExampleContentProvider
设计Content URIs(a. 设计authority b. 设计path c.处理content URI IDs d.Content URI patterns) 实现Provider中必须的方法(
query()insert()update()delete()getType()onCreate()getType()One of the required methods that you must implement for any provider. getStreamTypes()A method that you're expected to implement if your provider offers files.)ContentValues values = new ContentValues() ;values.put("WORD", "abcd") ;Uri uri = this.getContentResolver().insert(Uri.parse("content://com.hualu.contentprovider/mains"),values) ;String id = uri.getPathSegments().get(1) ;Cursor cAll = this.getContentResolver().query(Uri.parse("content://com.hualu.contentprovider/mains"), null, null, null,null);Cursor c = this.getContentResolver().query(Uri.parse("content://com.hualu.contentprovider/main/1"), null, null, null,null);Toast.makeText(this, "insert success id = " + id + " ," +" \r\n All = " + cAll.getCount() + " , " +"\r\n one = " + c.getCount(),Toast.LENGTH_SHORT).show() ;代码下载地址:
Contentprovider应用: http://download.csdn.net/detail/luhuajcdd/5140008
调用ContentProvider应用:http://download.csdn.net/detail/luhuajcdd/5140027