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
- <uses-permission android:name="android.permission.READ_CONTACTS" />
The following code is used:
- Public class Activity01 extends ListActivity
- {
- Public void onCreate (Bundle savedInstanceState)
- {
- Super. onCreate (savedInstanceState );
- // Cursor gets the phone URI
- Cursor cursor = getContentResolver (). query (Phones. CONTENT_URI, null,
- Null );
- StartManagingCursor (cursor );
- String [] string = {Phones. NAME, Phones. NUMBER };
- Int [] intText = {android. R. id. text1, android. R. id. text2 };
- // Use simple_list_item_2 to display the name and number of the phone.
- ListAdapter adapter = new SimpleCursorAdapter (this, android. R. layout. simple_list_item_2, cursor, string, intText );
- SetListAdapter (adapter );
- }
- }