The reason is that when we put the data into the database, the database permissions are private, the system of SMS application in the database export, open to see the address field is the phone number,date field is the time ,The type field 1,2 represents the sent SMS and the received SMS,body The field represents the data for the SMS. To allow other applications to access data from their own databases, you need to expose the data yourself.
Create a new class such as Personprovider, first inherit the system's ContentProvider class, this class is android One of the four components, exposing their own private data, other applications through the contentresolver class to obtain data. Components must be configured in the manifest file when they are applied
Under the application node, add a node <provider android:name="full class name" android:authorities= "host name" > </Provider>
Name Specifies the full class name of the content provider
Authorities represents the host name, usually the package name + Business name
Tips, in the list of files on the left of Eclipse , Click the plus sign next to the class we created, see the defined class, right - ==> copy qualified name copy full class name, package name plus class name
This time will be reported yellow warning, said that you need to set permissions android:permission, you can not set
After inheritance, you need to implement the following methods:
Query () queries
Insert () insertion
Delete () remove
Update () modification
Have a parameter URI object that represents a path an address, we need to check this URI
Manifest file:
< provider Android:name = "Com.tsh.database.PersonDbProvider" android:authorities= "Com.tsh.database.PersonDbProvider"> </ provider >
Provided by:
Packagecom.tsh.database;ImportAndroid.content.ContentProvider;Importandroid.content.ContentValues;ImportAndroid.database.Cursor;ImportAndroid.net.Uri; Public classPersondbproviderextendsContentProvider {@Override Public BooleanonCreate () {//TODO auto-generated Method Stub return false; } @Override PublicCursor query (Uri uri, string[] projection, string selection, string[] Selectionargs, string sortOrder) { //TODO auto-generated Method Stub return NULL; } @Override PublicString getType (Uri uri) {//TODO auto-generated Method Stub return NULL; } @Override Publicuri insert (URI uri, contentvalues values) {//TODO auto-generated Method Stub return NULL; } @Override Public intDelete (Uri Uri, String selection, string[] selectionargs) {//TODO auto-generated Method Stub return0; } @Override Public intupdate (URI Uri, contentvalues values, String selection, string[] selectionargs) {//TODO auto-generated Method Stub return0; }}
[Android] Content provider profile