So in an app I am building I fetch all the contacts within the phone and display it in a list view. Everything worked fine up until I upgraded my phone(HTC One)from 4.1.2 to 4.4.2. I no longer get images/profile pics of contacts instead it throws a FileNotFoundException. Also this happens only for a few contacts and not all. I am able to get the pictures from a few contacts and it fails for a few. The same piece of code works absolutely fine on a Nexus 5 running 4.4.2.
Here is the code which I use for querying the Contacts :
ContentResolver cr = getActivity().getContentResolver();
String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.PHOTO_URI,
ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI, ContactsContract.CommonDataKinds.Phone.CONTACT_ID};
String SELECTION =
(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME_PRIMARY) +
"<>''" + " AND " + Contacts.IN_VISIBLE_GROUP + "=1";
String sortBy = ContactsContract.Contacts.DISPLAY_NAME
+ " COLLATE LOCALIZED ASC";
Cursor people = cr.query(uri, projection, SELECTION + " AND " + ContactsContract.CommonDataKinds.Phone.HAS_PHONE_NUMBER
+ "=1", null, sortBy);
The logcat error which I get is :
System.out(17898): resolveUri failed on bad bitmap uri: content://com.android.contacts/contacts/289/photo
ImageView(17898): Unable to open content: content://com.android.contacts/contacts/289/photo
ImageView(17898): java.io.FileNotFoundException: content://com.android.contacts/contacts/289/photo?restricted=true
ImageView(17898): at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
ImageView(17898): at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:737)
Any ideas as to what could be the problem? Any suggestions?
Thanks in advance
Edit : I build a custom object named Contact with all the details and set it to a custom adapter. Here is the code where I set the photo in the imageview, though I don't think this is relevant :
if(contact != null){
viewHolder.contactName.setText(contact.getName());
if(contact.getThumbUri() != null){
viewHolder.contactThumb.setImageURI(Uri.parse(contact.getThumbUri()));
}else{
viewHolder.contactThumb.setImageResource(R.drawable.ic_launcher);
}
if(contact.isTlknUser()){
isTlkn[position] = true;
}
}