0

我正在开发一个 android 应用程序,我在其中显示呼叫日志和呼叫的详细信息。

我想在通话记录中显示联系人图片。我能够从联系人 ID 中获取联系人 ID 和 uri,但我得到所有联系人的以下异常:

java.io.FileNotFoundException: File does not exist; URI: content://com.android.contacts/contacts/171

这是我尝试过的以下代码:

Cursor managedCursor = getContentResolver().query( CallLog.Calls.CONTENT_URI,null, null,null,  android.provider.CallLog.Calls.DEFAULT_SORT_ORDER);
while ( managedCursor.moveToNext() )
{
  contactId = getContactIDFromNumber(phNumber,this);
  Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);

}
 public static int getContactIDFromNumber(String contactNumber,Context context)
 {
    int phoneContactID = new Random().nextInt();
    Cursor contactLookupCursor = context.getContentResolver().query(Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,Uri.encode(contactNumber)),new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID}, null, null, null);
    while(contactLookupCursor.moveToNext()){
        phoneContactID = contactLookupCursor.getInt(contactLookupCursor.getColumnIndexOrThrow(PhoneLookup._ID));
    }
    contactLookupCursor.close();

    return phoneContactID;
}


  public static Bitmap getContactBitmapFromURI(Context context, Uri uri)
  {
    InputStream input = null;
    try
    {
        input = context.getContentResolver().openInputStream(uri);  

        //input = Contacts.openContactPhotoInputStream(context.getContentResolver(), uri);
    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
    }
    if (input == null)
    {
        return null;
    }   

    return BitmapFactory.decodeStream(input);
}
4

0 回答 0