Read mobile phone contacts under Android SDK 1.6

Source: Internet
Author: User

Android 2.0 and later versions have made significant changes to contacts and other related APIs. Therefore, it is not recommended to port operations on Android 1.6 to Android 2.0. Here is a simple description of the operation method in SDK1.6.
Do not forgetAndroidManifest. xmlAdd the permission to read contacts

 
 
  1. <uses-permission android:name="android.permission.READ_CONTACTS" /> 

The following code is used:

 
 
  1. Public class Activity01 extends ListActivity
  2. {
  3. Public void onCreate (Bundle savedInstanceState)
  4. {
  5. Super. onCreate (savedInstanceState );
  6. // Cursor gets the phone URI
  7. Cursor cursor = getContentResolver (). query (Phones. CONTENT_URI, null,
  8. Null );
  9. StartManagingCursor (cursor );
  10. String [] string = {Phones. NAME, Phones. NUMBER };
  11. Int [] intText = {android. R. id. text1, android. R. id. text2 };
  12. // Use simple_list_item_2 to display the name and number of the phone.
  13. ListAdapter adapter = new SimpleCursorAdapter (this, android. R. layout. simple_list_item_2, cursor, string, intText );
  14. SetListAdapter (adapter );
  15. }
  16. }

Related Article

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.