从电话簿我怎样才能在Android应用程序联系号码和照片 [英] from phoneBook how can i get contact number and photo in android application
本文介绍了从电话簿我怎样才能在Android应用程序联系号码和照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要去,使该电话簿我访问联系人形成了android
i am going to make a phone book for that i access the contact form the android
推荐答案
//访问联系人照片
public static Bitmap loadContactPhoto(ContentResolver cr, long id) {
Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
if (input == null) {
return null;
}
return BitmapFactory.decodeStream(input);
}
//调用方法
Bitmap bitmap = loadContactPhoto(getContentResolver(), _id);
imageView.setImageBitmap(bitmap);
//获取数
private void getAllNumbers(long id) {
//Getting numbers
Cursor phones = null;
try {
phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[]{Phone.NUMBER, Phone.TYPE},
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ id,
null,
null);
if(phones != null) {
while(phones.moveToNext()){
switch(phones.getInt(phones.getColumnIndex(Phone.TYPE))){
case Phone.TYPE_MOBILE :
mobilePhone = phones.getString(phones.getColumnIndex(Phone.NUMBER));
break;
case Phone.TYPE_HOME :
homePhone = phones.getString(phones.getColumnIndex(Phone.NUMBER));
break;
case Phone.TYPE_WORK :
workPhone = phones.getString(phones.getColumnIndex(Phone.NUMBER));
break;
case Phone.TYPE_OTHER : // You can store other number also
}
}
}
} catch (Exception e) {
//Handle exception
} finally {
if(!phones.isClosed() || phones != null)
phones.close();
}
}
快乐编码。
这篇关于从电话簿我怎样才能在Android应用程序联系号码和照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文