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.
-
did you actually get the accepted answer to work in a widget? I don't see how you can add a QuickContactBadge to a widget. Even on Android 2.2.1, I'm getting W/AppWidgetHostView(20284): Error inflating AppWidget AppWidgetProviderInfo(provider=ComponentInfo{com.mypackage.xyz/c om.com.mypackage.xyz.FeedsWidget}): android.view.InflateException: Binary XML file line #131: Error inflating class androi d.widget.QuickContactBadge --- since it's not a supported component. – Mathias Conradt Dec 14 '10 at 04:39
4 Answers
To show the QuickContact UI over a widget, you can make a callback PendingIntent using the technique illustrated here:
http://advback.com/android/working-with-app-widgets-android/
In your widget onUpdate(), create the intent and associate it with the RemoteView:
intent = new Intent(context, MyWidget.class);
intent.setAction(ACTION_WIDGET_RECEIVER);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
intent.setData(uri);
pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.my_widget_view, pendingIntent);
When the view is clicked, you'll get an onReceive() notification in your widget. Use Intent.getSourceBounds() to retrieve the rect, and show the QuickContact:
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
Uri uri = intent.getData();
if ( uri != null ) {
QuickContact.showQuickContact(context, intent.getSourceBounds(), uri, ContactsContract.QuickContact.MODE_SMALL, null);
}
}
super.onReceive(context, intent);
}

- 3,879
- 1
- 36
- 34
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);

- 204,586
- 122
- 423
- 502
-
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 Aug 08 '10 at 21:01
-
sorry there is a missing line `mPhotoView = (QuickContactBadge) findViewById(R.id.photo);` – Pentium10 Aug 08 '10 at 21:15
-
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 Aug 09 '10 at 01:51
-
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 Aug 09 '10 at 08:50
-
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? – stfn Aug 27 '10 at 13:52
-
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 Aug 27 '10 at 14:05
-
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 Conradt Oct 09 '10 at 19:29
I've been struggling with this for some time now too. Looking at the Android source code, it appears that Google made a transparent activity called QuickContactActivity and placed the QuickContactWindow (the class that creates the popup) inside of that. I tried the same thing and the transparent activity does work but I'm having trouble getting the badge to show up. I know about Qberticus's QuickActions code and I did try it out but I'd rather just use the quickcontacts that google wrote because to duplicate its functionality and looks is pretty challenging.
I've also been getting ActivityNotFoundException when I try to use the QuickContact.showQuickContact() method on Eclair - it works great on Froyo though.
Here's my question. It would be really awesome if we could work together to get this issue solved: link