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}, null, null, null);
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();
}
}
안드로이드 주소록에서 이름, 연락처, 이미지 가져오기
댓글 없음:
댓글 쓰기