在图像视图中显示联系人图像
我想获取联系人图像并将其显示在图像视图中。我希望它能够根据用户选择的联系人来工作。我有一个按钮,用户按下它即可获取联系电话号码并将其显示在文本字段中。但现在我需要它来获取照片并显示它。有人知道我如何操纵它来获取照片吗? (忽略显示电子邮件的日志和显示电子邮件的变量,我操纵了代码,因此它获取了电话号码。)
case CONTACT_PICKER_RESULT:
Cursor cursor = null;
String email = "";
try {
Bundle extras = data.getExtras();
Set<String> keys = extras.keySet();
Iterator<String> iterate = keys.iterator();
while (iterate.hasNext()) {
String key = iterate.next();
Log.v(DEBUG_TAG, key + "[" + extras.get(key) + "]");
}
Uri result = data.getData();
Log.v(DEBUG_TAG,
"Got a contact result: " + result.toString());
// get the contact id from the Uri
String id = result.getLastPathSegment();
// query for everything email
cursor = getContentResolver().query(Phone.CONTENT_URI,
null, Phone.CONTACT_ID + "=?", new String[] { id },
null);
int emailIdx = cursor.getColumnIndex(Phone.DATA);
// let's just get the first email
if (cursor.moveToFirst()) {
/*
* Iterate all columns. :) String columns[] =
* cursor.getColumnNames(); for (String column :
* columns) { int index = cursor.getColumnIndex(column);
* Log.v(DEBUG_TAG, "Column: " + column + " == [" +
* cursor.getString(index) + "]"); }
*/
email = cursor.getString(emailIdx);
Log.v(DEBUG_TAG, "Got email: " + email);
} else {
Log.w(DEBUG_TAG, "No results");
}
} catch (Exception e) {
Log.e(DEBUG_TAG, "Failed to get email data", e);
} finally {
if (cursor != null) {
cursor.close();
}
EditText emailEntry = (EditText) findViewById(R.id.txtPhoneNo);
emailEntry.setText(email);
if (email.length() == 0) {
Toast.makeText(this, "No email found for contact.",
Toast.LENGTH_LONG).show();
}
}
break;
}
} else {
Log.w(DEBUG_TAG, "Warning: activity result not ok");
}
}
I want to get a contacts image and display it in an imageview. I want this to work based on what contact the user chooses. I have a button that has the user press it and get contact phone number and display it in a text field. but now i need it to get a photo and display it. does anybody have an idea of how i can manipulate this to get photos?
(ignore the logs that say email and my variables that say email, i manipulated the code so it gets phone numbers instead.)
case CONTACT_PICKER_RESULT:
Cursor cursor = null;
String email = "";
try {
Bundle extras = data.getExtras();
Set<String> keys = extras.keySet();
Iterator<String> iterate = keys.iterator();
while (iterate.hasNext()) {
String key = iterate.next();
Log.v(DEBUG_TAG, key + "[" + extras.get(key) + "]");
}
Uri result = data.getData();
Log.v(DEBUG_TAG,
"Got a contact result: " + result.toString());
// get the contact id from the Uri
String id = result.getLastPathSegment();
// query for everything email
cursor = getContentResolver().query(Phone.CONTENT_URI,
null, Phone.CONTACT_ID + "=?", new String[] { id },
null);
int emailIdx = cursor.getColumnIndex(Phone.DATA);
// let's just get the first email
if (cursor.moveToFirst()) {
/*
* Iterate all columns. :) String columns[] =
* cursor.getColumnNames(); for (String column :
* columns) { int index = cursor.getColumnIndex(column);
* Log.v(DEBUG_TAG, "Column: " + column + " == [" +
* cursor.getString(index) + "]"); }
*/
email = cursor.getString(emailIdx);
Log.v(DEBUG_TAG, "Got email: " + email);
} else {
Log.w(DEBUG_TAG, "No results");
}
} catch (Exception e) {
Log.e(DEBUG_TAG, "Failed to get email data", e);
} finally {
if (cursor != null) {
cursor.close();
}
EditText emailEntry = (EditText) findViewById(R.id.txtPhoneNo);
emailEntry.setText(email);
if (email.length() == 0) {
Toast.makeText(this, "No email found for contact.",
Toast.LENGTH_LONG).show();
}
}
break;
}
} else {
Log.w(DEBUG_TAG, "Warning: activity result not ok");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用它
并了解更多信息,请访问此问题
在列表视图性能中加载联系人照片< /a>
Use it
And for more information go to this question
Load contact photo in a listview performance
查看 中的 openContactPhotoInputStream(android.content.ContentResolver,android.net.Uri) http://developer.android.com/reference/android/provider/ContactsContract.Contacts.html
Check out openContactPhotoInputStream(android.content.ContentResolver,android.net.Uri)in http://developer.android.com/reference/android/provider/ContactsContract.Contacts.html