private String[] getContacts() { Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String[] projects = new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}; Cursor cursor = getContentResolver().query(uri,projects,null,null,null); String[] contacts = null; int index=0; try{ Log.i("Contact-C","count : "+cursor.getCount()); contacts = new String[cursor.getCount()]; cursor.moveToFirst(); while (!cursor.isAfterLast()){ String name = cursor.getString(0); String number = cursor.getString(1); Log.i("Contact-C",name+" : "+number+" --------------- index = "+index); contacts[index] = name+" : "+number; index++; cursor.moveToNext(); } }finally { index = 0; cursor.close(); } return contacts; }
Demo下载链接: github demo,在NormalDemo/app/build/outputs/apk/debug下有Demo apk可直接安装运行查看效果