如何从小部件显示 QuickContact 卡

发布于 2024-09-13 05:41:46 字数 203 浏览 6 评论 0 原文

我有一个小部件,可以显示我的一些联系人的图片,我想在用户点击其中一张图片时显示 QuickContact 卡。我知道我应该使用 ContactsContract.QuickContact.showQuickContact() 方法,但它需要视图或矩形作为输入参数之一。我的问题是小部件只有 RemoteViews,所以我不确定要传递什么作为 View 或 Rect 参数。任何想法将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

怕倦 2024-09-20 05:41:46

要通过小部件显示 QuickContact UI,您可以使用此处说明的技术进行回调 PendingIntent:

http://advback.com/android/working-with-app-widgets-android/

在您的小部件 onUpdate() 中,创建意图并将其与 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);

单击视图时,您将在小部件中收到 onReceive() 通知。使用 Intent.getSourceBounds() 检索矩形,并显示 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);
}  

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);
}  
知足的幸福 2024-09-20 05:41:46

您可以在 XML 中引用徽章

我在 XML 文件中有这个:

     <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"
     />

和此代码:

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

这是调用模式(但是单击徽章正在处理此弹出窗口,此调用也是弹出窗口,选择器是通过单击某些内容进行的别的)

QuickContact.showQuickContact(viewContactQuick.this, mPhotoView,objItem.getLookupUri() , QuickContact.MODE_MEDIUM, null);

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);
焚却相思 2024-09-20 05:41:46

我也一直在寻找这个。也许通讯录应用程序的来源会有所帮助。我正在尝试挖掘: 链接文本

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

小…楫夜泊 2024-09-20 05:41:46

我也为此苦苦挣扎了一段时间。查看 Android 源代码,Google 似乎创建了一个名为 QuickContactActivity 的透明活动,并将 QuickContactWindow(创建弹出窗口的类)放置在其中。我尝试了同样的操作,透明活动确实有效,但我无法显示徽章。我了解 Qberticus 的 QuickActions 代码,并且确实尝试过,但我宁愿只使用 google 编写的 Quickcontacts,因为复制其功能和外观非常具有挑战性。

当我尝试在 Eclair 上使用 QuickContact.showQuickContact() 方法时,我也遇到了 ActivityNotFoundException - 不过它在 Froyo 上效果很好。

这是我的问题。如果我们能够共同努力解决这个问题,那就太棒了:链接

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文