본문 바로가기
#모바일 [Mobile]/Android

[Android] 연락처 제공자 (Contact Provider)

by cy_mos 2019. 6. 24.
반응형

📣 연락처 제공자 (Contact Provider)

  • The Contacts Provider is a powerful and flexible Android component that manages the device's central repository of data about people. The Contacts Provider is the source of data you see in the device's contacts application, and you can also access its data in your own application and transfer data between the device and online services. The provider accommodates a wide range of data sources and tries to manage as much data as possible for each person, with the result that its organization is complex.
📷 Contact Provider Image 001 📷 Contact Provider Image 002

📄 연락처 제공자 (Contact Provider) Manifest Source Code
<uses-permission android:name="android.permission.READ_CONTACTS"/>    // Read Permission
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>   // Write Permission
📄 연락처 제공자 (Contact Provider) Source Code
final Cursor cursor = getContentResolver().query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,     // 조회할 컬럼명
                null,
                null,
                null,
                null
);

cursor.moveToFirst();
do {
          final Pair<Integer, Integer> index = Pair.create(
                    cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME),
                    cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)
          );

          System.out.println( String.format("※ TEL -> Name: %s, Phone: %s", cursor.getString(index.first), cursor.getString(index.second)) );

} while ( cursor.moveToNext() );

📣 REFERENCE

반응형

댓글