从手机添加用户的联系人的照片的ListView? :D [英] Adding the user's contact's photo from phone to ListView? :D
问题描述
我在用户手机创建联系人列表,现在我想添加的用户的照片(不是从FB)如何创建? :D
这是我的一块code的:
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main); ContentResolver的CR = getContentResolver();
光标光标= cr.query(Uri.parse(内容://短信/收件箱),NULL,NULL,
NULL,NULL); INT indexBody = cursor.getColumnIndex(身体);
INT indexAddr = cursor.getColumnIndex(地址); 如果(indexBody<!0 || cursor.moveToFirst())
返回; smsList.clear(); 做{
字符串str =发件人:+ cursor.getString(indexAddr)+\\ n
+ cursor.getString(indexBody);
smsList.add(STR);
//地址[总] = cursor.getString(indexAddr);
//总++;
}而(cursor.moveToNext()); ListView控件lvSms =(ListView控件)findViewById(R.id.SMSList);
lvSms.setAdapter(新ArrayAdapter<串GT;(这一点,
android.R.layout.simple_list_item_1,smsList)); // cursor.requery();
lvSms.setOnItemClickListener(本);
}
我在code创建列表:
{做
字符串str =发件人:+ cursor.getString(indexAddr)+\\ n
+ cursor.getString(indexBody);
smsList.add(STR);
//地址[总] = cursor.getString(indexAddr);
//总++;
}而(cursor.moveToNext()); ListView控件lvSms =(ListView控件)findViewById(R.id.SMSList);
lvSms.setAdapter(新ArrayAdapter<串GT;(这一点,
android.R.layout.simple_list_item_1,smsList)); // cursor.requery();
lvSms.setOnItemClickListener(本);
这就是所有,我发现我必须使用位图,是真的吗?
感谢所有:D
PS:英语不是我的母语的语,很抱歉,如果我做了一些错误的:D
乌里contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI,
的ContactID);
乌里photoUri = Uri.withAppendedPath(contactUri,
Contacts.Photo.CONTENT_DIRECTORY);
光标光标= getContentResolver()查询(photoUri,NULL,NULL,NULL,
空值);
使用此查询您可以为用户照片在联系人列表中提取图片的URL
,以便与姓名和号码在列表中显示沿,你必须Base或任何其他自定义的适配器。
I have created a list of contact's in user phone, now i want to add the user's photo (not from fb) how to create that? :D This is a piece of my code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(Uri.parse("content://sms/inbox"), null, null,
null, null);
int indexBody = cursor.getColumnIndex("body");
int indexAddr = cursor.getColumnIndex("address");
if (indexBody < 0 || !cursor.moveToFirst())
return;
smsList.clear();
do {
String str = "Sender : " + cursor.getString(indexAddr) + "\n"
+ cursor.getString(indexBody);
smsList.add(str);
// ADDRESS[total] = cursor.getString(indexAddr);
// total++;
} while (cursor.moveToNext());
ListView lvSms = (ListView) findViewById(R.id.SMSList);
lvSms.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, smsList));
// cursor.requery();
lvSms.setOnItemClickListener(this);
}
I create the list in this code :
do {
String str = "Sender : " + cursor.getString(indexAddr) + "\n"
+ cursor.getString(indexBody);
smsList.add(str);
// ADDRESS[total] = cursor.getString(indexAddr);
// total++;
} while (cursor.moveToNext());
ListView lvSms = (ListView) findViewById(R.id.SMSList);
lvSms.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, smsList));
// cursor.requery();
lvSms.setOnItemClickListener(this);
Thats all, i found that i must use Bitmap, is it true? Thanks all :D
PS : English is not my native languange, so sorry if i made some mistake's :D
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI,
contactId);
Uri photoUri = Uri.withAppendedPath(contactUri,
Contacts.Photo.CONTENT_DIRECTORY);
Cursor cursor = getContentResolver().query(photoUri, null, null, null,
null);
using this query you can fetch the image url for your user photos in your contact list, in order to display along with name and number in list , you have to Base or any other custom adapter.
这篇关于从手机添加用户的联系人的照片的ListView? :D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!