Call the contacts selection interface provided by Android, android contacts
You often need to select a contact in a project. If there is no special invitation, the contact interface provided by the system is sufficient:
Test Platform: android 4.2
Display Effect: 1 Intent intent = new Intent (Intent. ACTION_GET_CONTENT); 2 intent. setType (ContactsContract. CommonDataKinds. Phone. CONTENT_ITEM_TYPE); 3 startActivityForResult (intent, 1 );
To obtain the selected contact information, you must rewrite onActivityResult.
1 @Override 2 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 3 super.onActivityResult(requestCode, resultCode, data); 4 if (data != null) { 5 Uri uri = data.getData(); 6 if (uri != null) { 7 Cursor cursor = getContentResolver() 8 .query(uri, 9 new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME },10 null, null, null);11 while (cursor.moveToNext()) {12 String number = cursor.getString(0);13 String name = cursor.getString(1);14 }15 16 }17 }18 19 }