마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

주소록 사진 가져오는 방법이 너무 어렵습니다.

0 추천
/**
 * 주소록 리스트 호출
 */
public void getList() {

    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] projection = new String[]{
            ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
            ContactsContract.CommonDataKinds.Phone.NUMBER,
            ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME


    };
    String[] selectionArgs = null;

    // 정렬
    String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

    // 조회해서 가져온다
    Cursor contactCursor = null;



try {



        // 정보를 담을 array 설정
        ArrayList<String> persons = new ArrayList<String>(contactCursor.getCount());

        if (contactCursor.moveToFirst()) {

            do {

                persons.add(contactCursor.getString(2) + "/" +contactCursor.getString(1) + "/" + contactCursor.getString(0)+"/");






            } while (contactCursor.moveToNext());

        }
        tempList = persons;


        Log.w("로그확인", String.valueOf(tempList));
        Log.w("로그확인", String.valueOf(tempList));
        Log.w("로그확인", String.valueOf(tempList));


        showList(persons);



    } catch (Exception e) {

        e.printStackTrace();

    } finally {

        if (contactCursor != null) {
            //  contactCursor.close();
            // cursor 닫아 버리면 해당 다음 액티비티가 호출되고 다시 넘어가려고 할때 에러가 걸리게 된다 그래서 주석처리

        } // end if (contactCursor != null)




    } // end try

} // end getList

어탭터를 따로 두어서 리스트뷰에 배열로 사진을 뿌리고 싶은데 다른 예제가 참고가 안되서 헤갈리네요 
 
persons.add(contactCursor.getString(2) + "/" +contactCursor.getString(1) + "/" + contactCursor.getString(0)+"/");  이부분은 어답터에서 split 나누어서 가져오는 정보로 0 = 이름 1= 전화번호 2 = content id  값 입니다.
익명사용자 님이 2017년 5월 22일 질문

1개의 답변

0 추천
순차적으로 하세요.

먼저 화면에 리스트를 어떻게 출력할 수 있는지 마스터 하시고 그 다음 주소록을 고민하세요

주소록에 대한 코드는 https://github.com/apache/cordova-plugin-contacts/tree/master/src/android 를 참고하세요
aucd29 (218,390 포인트) 님이 2017년 5월 23일 답변
...