tags:

views:

86

answers:

1

I notice that some of the base applications in Android are using this little control (View in Android terms I guess) that shows the contact picture. When you click on the picture it shows all the ways of contacting the person (phone, sms, talk, facebook). I see this little View used in the contact app, sms app, twitter for android, facebook for android etc.

Is there a library or a way of getting this working on my own application or do I need to write this from scratch?

+2  A: 

You can reference the QuickContactBadge in the XML

I have this in the XML file:

     <QuickContactBadge
     android:id="@+id/photo"
    android:layout_width="54dip"
    android:layout_height="57dip"
    android:layout_marginLeft="5dip"
    android:background="@drawable/quickcontact_photo_frame"
    style="?android:attr/quickContactBadgeStyleWindowSmall"
     />

and this code:

private QuickContactBadge mPhotoView;
mPhotoView = (QuickContactBadge) findViewById(R.id.photo);
mPhotoView.assignContactUri(objItem.getUri());
mPhotoView.setMode(QuickContact.MODE_MEDIUM);

and this is the calling mode (but the click on the badge is handling this popup, this call to popup the chooser is made by clicking on something else, you don't need if you just want the quick contact to show when clicking on the badge, that's already built in)

QuickContact.showQuickContact(viewContactQuick.this, mPhotoView,objItem.getLookupUri() , QuickContact.MODE_MEDIUM, null);
Pentium10
Thank you. Very useful.
dineth
Pentium10, your code works fine in 2.2, but when I run the same on 2.1, I'm getting an error as below - do you know why? android.content.ActivityNotFoundException: No Activity found to handle Intent { act= com.android.contacts.action.QUICK_CONTACT dat=content://contacts/people/2177
Mathias Lin
It's the first time when I hear this. Probably the Android distribution of that 2.1 device is missing this QUICK_CONTACT class, as this should be built inside android. Or you are doing something wrong in the code especially don't use `getApplicationContext()` to pass a context, instead pass an activity or service to it
Pentium10
I also tested it on the emulator avd 2.1, same error. On an 2.2 avd as well as on my Nexus One 2.2, it also works fine.
Mathias Lin
Just curious: why do you actually need the QuickActionBadge at all? I can also call the QuickContact.showQuickContact on any view. I.e. I'm simply passing a ListItem (view) of a ListView as the second parameter and it works (on 2.2).
Mathias Lin
I'm on SGS with 2.1update1. The system's contacts app does show the QuickContactBadge, so I guess the Android distribution must have it. I'm passing the ApplicationContext, the code is here: http://pastebin.com/Q50vi66A
Mathias Lin
Have you tried what I've told in my last comment? I repeat, I've told to NOT use `getApplicationContext()`, change it to your activity. IF you change to activity does it work?
Pentium10
I also tried to use the activity as context itself, was no difference. But I just see what the problem was. I was using an insert-uri instead of a lookup-uri. Now it's ok also on 2.1, but I'm wondering why it was working on 2.2 before and not on 2.1.
Mathias Lin
I can't tell you that.
Pentium10