[Android] Content provider profile

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.