Use the Content Provider defined by the System

Source: Internet
Author: User

Previously, we introduced Content about Content Provider. Here we will introduce the Content Provider defined by the system and the custom Content Provider in two sections.

Here we will introduce how to use the system-defined Content Provider: to read the contact information of the system through ContentResolver.

Step 1: Create a new project named readPeople. Because the project is displayed as a list, this class inherits from listavti.pdf instead of Activity;

Step 2: modify the java Source Code. The Code is as follows:


View plaincopy to clipboardprint? /** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// SetContentView (R. layout. main );
// Obtain the cursor object
Cursor c = getContentResolver (). query (ContactsContract. Contacts. CONTENT_URI, null );
This. startManagingCursor (c );

// Instantiate the list Adapter
StAdapter adapter = new SimpleCursorAdapter (this, android. r. layout. simple_list_item_1, c, new String [] {Contacts. DISPLAY_NAME}, new int [] {android. r. id. text1 });
This. setListAdapter (adapter );
}
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// SetContentView (R. layout. main );
// Obtain the cursor object
Cursor c = getContentResolver (). query (ContactsContract. Contacts. CONTENT_URI, null );
This. startManagingCursor (c );

// Instantiate the list Adapter
ListAdapter adapter = new SimpleCursorAdapter (this, android. r. layout. simple_list_item_1, c, new String [] {Contacts. DISPLAY_NAME}, new int [] {android. r. id. text1 });
This. setListAdapter (adapter );
} View plaincopy to clipboardprint? Step 3: Add the following content to the AndroidManifestxml file: <uses-permission android: name = "android. permission. READ_CONTACTS"/>
Step 3: Add the following content to the AndroidManifestxml file: <uses-permission android: name = "android. permission. READ_CONTACTS"/> Step 4: run the program to see the following content:




From the column chenlong12580

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.