Content providers are used to save and retrieve data so that data can be shared between different applications in the Android system. Provide data in the form of a URI.
First use a class to inherit the Android.content package under Contentprovide, rewrite the method.
1.public Boolean oncreare () is called when Contentprovide is created.
2. the public int delete (URI Uri, String selection, string[] selectionargs) deletes the specified data.
3. Public URI insert (URI uri, contentvalues values) inserts data
4. public int update (URI uri, contentvalues values, String selection, string[] selectionargs) updates the data under the specified conditions
5. Public Cursor query (URI uri, string[] projection, string selection, string[] Selectionargs, string sortOrder) queries the data for the specified condition
6. Public String GetType (URI uri) returns the MIME type of the URI that represents the data
Second write Uri, by Content://authorities/path
authorities refers to the value of android:authorities registered in the manifest file
Path represents data, dynamic change
Such as:
Private StaticUrimatcher matcher=NewUrimatcher (Urimatcher.no_match); Private Static Final intInsert=1; Private Static Final intdelete=2; Private Static Final intUpdate=3; Private Static Final intQuery=4; Private Static Final intQueryone=5; Static{Matcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "Insert", INSERT); Matcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "delete", DELETE); Matcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "Update", UPDATE); Matcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "Query", QUERY); //#为通配符, all "query/" are returned with the return code of QueryoneMatcher.adduri ("Com.lss.readcontactmassage.PersonDBProvider", "query/#", Queryone); }
public int match (URI uri) returns the code value of the parameter passed in the Adduri method
Android ContentProvider Understanding