ContentProvider Data Provider
Data transfer between the program and the program.
ContentProvider provides a method for calling other programs to invoke the internal data of the program.
/** Used to define what other programs can do when they call the program data. */ Public classMycontentproviderextendsContentProvider {@Override//called after ContentProvider has been created Public BooleanonCreate () {//TODO auto-generated Method Stub return false; } @Override//Insert the valuse corresponding data according to the URI Publicuri insert (URI uri, contentvalues values) {//TODO auto-generated Method Stub return NULL; } @Override//deletes all records that match the specified criteria (selection and Selectionargs) based on the URI Public intDelete (Uri arg0, String selection, string[] selectionargs) {//TODO auto-generated Method Stub return0; } @Override//all records that match the specified criteria (selection and Selectionargs) based on the URI query, projection (column name), SortOrder (sort) PublicCursor query (Uri uri, string[] projection, string selection, string[] Selectionargs, string sortOrder) { //TODO auto-generated Method Stub return NULL; } @Override//Modifies all records that match the specified criteria (selection) According to the URI, modifying the data corresponding to values Public intupdate (URI Uri, contentvalues values, String selection, string[] selectionargs) {//TODO auto-generated Method Stub return0; } @Override//returns the MIME type of the current URI if the URI corresponding data may contain more than one record//then the MIME type string begins with vnd.android.dir///If there is only one URI corresponding to the data, then the MIME type string begins with vnd.android.cursor.item/ PublicString getType (Uri uri) {//TODO auto-generated Method Stub return NULL; }}
Remember to register:
<provider android:name= ". Mycontentprovider " android:authorities=" Com.example.z_contentprovider "> </provider >
The general method of calling ContentProvider is through the URI object
You can also call the system's ContentProvider
/*** Data Provider ContentProvider: * Four components, storage mode, can process data across programs * Other forms of storage are simply shared in a single program * cannot invoke data from other programs*//*** When other programs call a custom contentprovider, you need to record the authorization information with a common Resource table character (Uri) * android:authorities= "Com.example.z_contentprovider" * This is a property that needs to be composed in Androidmanifest.xml using ContentProvider, which is the name of the authorization record. */ Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); /*** System-provided ContentProvider can call system SMS, contact person, picture music and other resources. * The Contentresolver object, like ContentProvider, provides a method for adding and deleting URIs. */contentresolver CP=Getcontentresolver (); Contentvalues Values=Newcontentvalues (); //cp.insert (URL, values); //cp.delete (URL, where, Selectionargs); //cp.update (URL, values, where, Selectionargs)//cp.insert (URL, values); }}
If there is any mistake, or I understand wrong or improper, I implore everyone to correct, thank you! Hey, hehe.
Android Four Components--contentprovider