Android - strange contact issue in Kitkat

So, in the application that I create, I extract all the contacts in the phone and display it in a list. Everything worked fine until I updated my phone (HTC One) from 4.1.2 to 4.4.2. I no longer receive contact image images / profiles; instead, it throws a FileNotFoundException. Also, this happens only for a few contacts and not for all. I can get photos from several contacts, and this fails for some. The same piece of code works absolutely fine on a Nexus 5 running 4.4.2.

Here is the code I use to request 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 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 on what might be the issue? Any suggestions?

Thanks in advance

: "" . , , , :

 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;
        }
    }
+4
1

, , , , . , , , , , Kitkat OEMS, .

0

Source: https://habr.com/ru/post/1536396/


All Articles