【问题标题】:Android get contact photo display picture if you have phone number如果您有电话号码,Android 会获取联系人照片显示图片
【发布时间】:2015-10-19 06:58:51
【问题描述】:

我有所有联系人日志,我想将联系人图像附加到电话号码,如果没有联系人图像,则为未知图像。

我该怎么做?我尝试了很多方法,但没有任何效果。

【问题讨论】:

标签: android contact photos


【解决方案1】:

这是官方文档中获取联系人图片的方法。

 public InputStream openPhoto(long contactId) {
 Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
 Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
 Cursor cursor = getContentResolver().query(photoUri,
      new String[] {Contacts.Photo.PHOTO}, null, null, null);
 if (cursor == null) {
     return null;
 }
 try {
     if (cursor.moveToFirst()) {
         byte[] data = cursor.getBlob(0);
         if (data != null) {
             return new ByteArrayInputStream(data);
         }
     }
 } finally {
     cursor.close();
 }
 return null;
} 

访问此链接link

【讨论】:

    猜你喜欢
    • 2015-04-01
    • 1970-01-01
    • 2017-08-11
    • 2014-01-14
    • 1970-01-01
    • 2013-09-16
    • 2013-05-19
    • 1970-01-01
    相关资源
    最近更新 更多