0

I am developing an android application, in which I am displaying call Logs and the Details of the calls.

I want to display the contact picture in the call Log. I am able to get the contact ID and the uri from the Contact id but I am getting the below exception for all the contacts:

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

Here is the below code which I tried:

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);
}
Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
LISA
  • 63
  • 2
  • 7
  • you can't have access to other app's data. If u've rooted your phone, you can bypass this restriction. – dumbfingers Jun 18 '13 at 11:54
  • @ss1271 : I guess its wrong – LISA Jun 18 '13 at 13:12
  • Try vikramjb answer here: http://stackoverflow.com/questions/7356796/getting-contact-id-from-android-contacts-database-is-not-working-as-intended/7374721#7374721 – walla Jan 23 '16 at 14:57

0 Answers0