티스토리 뷰
Manifast 추가
1 | <uses-permission android:name="android.permisstion.READ_CONTACTS" /> | cs |
1 | import android.database.Cursor; | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | String [] arrProjection = { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME }; // get user list Cursor clsCursor = 메인 컨텍스트.getContentResolver().query ( ContactsContract.Contacts.CONTENT_URI, arrProjection, ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1" , null, null ); while( clsCursor.moveToNext() ) { Log.d("Unity", "연락처 사용자 ID : " + clsCursor.getString( 0 )); Log.d("Unity", "연락처 사용자 이름 : " + clsCursor.getString( 1 )); } clsCursor.close( ); | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | public static void GetUserContactsList() { String [] arrProjection = { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME }; String [] arrPhoneProjection = { ContactsContract.CommonDataKinds.Phone.NUMBER }; String [] arrEmailProjection = { ContactsContract.CommonDataKinds.Email.DATA }; // get user list Cursor clsCursor = 메인 컨텍스트.getContentResolver().query ( ContactsContract.Contacts.CONTENT_URI, arrProjection, ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1" , null, null ); while( clsCursor.moveToNext() ) { String strContactId = clsCursor.getString( 0 ); Log.d("Unity", "연락처 사용자 ID : " + clsCursor.getString( 0 )); Log.d("Unity", "연락처 사용자 이름 : " + clsCursor.getString( 1 )); // phone number Cursor clsPhoneCursor = 메인 컨텍스트.getContentResolver().query ( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, arrPhoneProjection, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + strContactId, null, null ); while( clsPhoneCursor.moveToNext() ) { Log.d("Unity", "연락처 사용자 폰번호 : " + clsPhoneCursor.getString( 0 )); } clsPhoneCursor.close(); // email Cursor clsEmailCursor = 메인 컨텍스트.getContentResolver().query ( ContactsContract.CommonDataKinds.Email.CONTENT_URI, arrEmailProjection, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + strContactId, null, null ); while( clsEmailCursor.moveToNext() ) { Log.d("Unity", "연락처 사용자 email : " + clsEmailCursor.getString( 0 )); } clsEmailCursor.close(); // note String noteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] noteWhereParams = new String[]{ strContactId, ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE }; Cursor clsNoteCursor = 메인 컨텍스트.getContentResolver().query ( ContactsContract.Data.CONTENT_URI, null, noteWhere, noteWhereParams, null ); while( clsNoteCursor.moveToNext() ) { Log.d("Unity", "연락처 사용자 메모 : " + clsNoteCursor.getString(clsNoteCursor.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE)) ); } clsNoteCursor.close(); // address String addressWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] addressWhereParams = new String[]{ strContactId, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE }; Cursor clsAddressCursor = 메인 컨텍스트.getContentResolver().query ( ContactsContract.Data.CONTENT_URI, null, addressWhere, addressWhereParams, null ); while( clsAddressCursor.moveToNext() ) { Log.d("Unity", "연락처 사용자 주소 poBox : " + clsAddressCursor.getString(clsAddressCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POBOX)) ); Log.d("Unity", "연락처 사용자 주소 street : " + clsAddressCursor.getString(clsAddressCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET)) ); Log.d("Unity", "연락처 사용자 주소 city : " + clsAddressCursor.getString(clsAddressCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY)) ); Log.d("Unity", "연락처 사용자 주소 region : " + clsAddressCursor.getString(clsAddressCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION)) ); Log.d("Unity", "연락처 사용자 주소 postCode : " + clsAddressCursor.getString(clsAddressCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE)) ); Log.d("Unity", "연락처 사용자 주소 country : " + clsAddressCursor.getString(clsAddressCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY)) ); Log.d("Unity", "연락처 사용자 주소 type : " + clsAddressCursor.getString(clsAddressCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.TYPE)) ); } clsAddressCursor.close(); // Organization String orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] orgWhereParams = new String[]{ strContactId, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE }; Cursor clsOrgCursor = 메인 컨텍스트.getContentResolver().query ( ContactsContract.Data.CONTENT_URI, null, orgWhere, orgWhereParams, null ); while( clsOrgCursor.moveToNext() ) { Log.d("Unity", "연락처 사용자 회사 : " + clsOrgCursor.getString(clsOrgCursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DATA)) ); Log.d("Unity", "연락처 사용자 직급 : " + clsOrgCursor.getString(clsOrgCursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.TITLE)) ); } clsOrgCursor.close(); } clsCursor.close( ); } | cs |
'ANDROID > android' 카테고리의 다른 글
Android - push 알림 (notification) (0) | 2016.12.12 |
---|---|
Android - Alert 창 띄우기 (0) | 2016.12.02 |
Android - back 버튼 활용 (0) | 2016.11.28 |
Android - RXAndroid Retrofit (0) | 2016.11.14 |
Android Google Map 추가하기 (0) | 2016.11.10 |
Comments