views:

225

answers:

2

I have a widget that displays the picture of some of my contacts and I would like to display the QuickContact card when the user taps on one of the pictures. I know I should be using the method ContactsContract.QuickContact.showQuickContact(), but it requires a View or a Rect as one of the input parameters. My problem is that Widgets only have RemoteViews, so I'm no sure what to pass as the View or Rect parameter. Any ideas would be appreciated.

A: 

You can reference the badge 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 too popup the chooser is made by clicking on something else)

QuickContact.showQuickContact(viewContactQuick.this, mPhotoView,objItem.getLookupUri() , QuickContact.MODE_MEDIUM, null);
Pentium10
But what happens if you have more than one QuickContactBadge on the widget (home app). Your "private QuickContactBadge mPhotoView" does not link back to the XML, so how do you know which QuickContactBadge belongs to the private statement?Thanks
alejom99
sorry there is a missing line `mPhotoView = (QuickContactBadge) findViewById(R.id.photo);`
Pentium10
Is your code above defined within an Activity? The reason I'm asking is because findViewById() is not defined within the AppWidgetProvider. If that's the case, then do you define an Intent to open that activity (when the users taps the QuickContactBade) and then you display the QuickContact card?
alejom99
I have in an activity. The quick contact card opens from two objects. From the badge itself (it's already built in, I do not react to click events), but I also wanted to open when the contact name is clicked, there I raise it manually in the above mention way.
Pentium10
I am looking into this, too. Let me try to get it: you can actually place a QuickContactBadge as an App Widget? That's all I would need but I don't see how to a) assign the contact to the badge and b) show the QuickContactCard via a PendingIntent. Any hints?
steff
You can show the quick contact card via the above mentioned static way: see `showQuickContact` it needs a context to work and an object. You assign the contact to the badge via it's one of your params: see `getLookupUri()`. I haven't tried for the app widget, but I think if you got a context and an object you can show up. I don't see why you have said about PendingIntent.
Pentium10
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
A: 

I've been looking for this as well. Maybe the source of the Contacts app will be helpful. I'm trying to digg in: link text

steff