开发者

Trying to replicate android homescreen Contact shortcuts, with issues

Okay, I'm trying to replicate the shortcuts which get placed on the homescreen when creating a contact shortcut, example shown:

Trying to replicate android homescreen Contact shortcuts, with issues

I've got a working QuickContactBadge, which when clicked shows the QuickContact toolbar. However, I have two things I'm having trouble with.

One is the picture. I tried using the code from this question (I altered it by adding a parameter to pass in the contact ID). I then assign the image to my QuickContactBadge as so:

bdg.setImageURI(getPhotoUri(cid));

It definitely gets pictures, but it is getting TOTALLY the wrong picture. As illustrated here:

Trying to replicate android homescreen Contact shortcuts, with issues

As you can see, the image it returned for Domino's is clearly NOT the Domino's logo.

I'm getting my contact ID to pass to the function from this code:

    public static String[] ContactsProjection = new String[] {
            Contacts._ID,
            Contacts.LOOKUP_KEY, 
            Contacts.DISPLAY_NAME
    };

    public static Cursor getContacts() {
            ContentResolver cr = CoreLib.ContentResolver();
            Cursor contacts = cr.query(
                    Contac开发者_运维百科tsContract.Data.CONTENT_URI, 
                    ContactsProjection, 
                    null, null, 
                    Contacts.TIMES_CONTACTED + " DESC"
            );
        return contacts;
    }

Which I believe should be returning me the proper ID for each record. Yes?

Next how do I get exactly the thumbnail shrunk or cropped as the shortcut shows it?

I was a little disappointed to see that the QuickContactBadge doesn't actually replicate the whole look and feel of the QuickContact shortcut, ... but just acts as in invocation target for the QuickContact card. Is there any built in way to easily replicate the contact shortcut in it's entirety, invocation, image, text and all, without needing to reproduce the whole thing from scratch?


Ah HAH! Figured out how to get the correct photo. While this seems counter-intuitive, when building your field projection to query the contacts, the fields Contacts._ID and ContactsContract.Data.CONTACT_ID are not the same thing.

ContactsContract.Data.CONTACT_ID is the correct one to pass in to get the photo. Use this, and everything is now golden.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜