티스토리 뷰

public void getPhoneBookList(){

    Uri ContactsUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;

    

    

    String disId = ContactsContract.CommonDataKinds.Phone.CONTACT_ID;

    String disName = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME;

    String number = ContactsContract.CommonDataKinds.Phone.NUMBER;

    

    Cursor cursor = getContentResolver().query(ContactsUri, new String[]{disId, disName, number}, nullnullnull);

    Global.friendId = new long[cursor.getCount()];

    Global.friendPicture = new Bitmap[cursor.getCount()];

    Global.friendCount = cursor.getCount();

    Global.friendName = new String[cursor.getCount()];

    Global.friendNum = new String[cursor.getCount()];

    int i = 0;

    

    if(cursor != null){

    cursor.moveToFirst();

    while(!cursor.isAfterLast()){

    long id = Long.parseLong(cursor.getString(0));

    String name = cursor.getString(1);

    String phone = cursor.getString(2);

    

    ////처리~

    Global.friendId[i] = id;

    Global.friendName[i] = name;

    Global.friendNum[i] = phone;

    

    ContentResolver cr = getContentResolver();

    Uri imageUrl = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);

    InputStream io = ContactsContract.Contacts.openContactPhotoInputStream(cr, imageUrl);

    

    if(io != null){

    Bitmap photo = BitmapFactory.decodeStream(io);

    Global.friendPicture[i] = photo;

    }else{

    Global.friendPicture[i] = null;

    }

    

    i++;

    

    cursor.moveToNext();

    }

    cursor.close();

    

    }

 

 

 

 

안드로이드 주소록에서 이름, 연락처, 이미지 가져오기

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함