android: showquickcontact() 在 froyo 上效果很好,但在 eclair 上效果不佳,后者会抛出 ActivityNotFound 异常

发布于 2024-10-09 17:55:55 字数 1794 浏览 0 评论 0原文

这些天我用谷歌搜索了很多,但没能解决这个问题。我正在编写一个应用程序和一个小部件,当用户通过调用 QuickContact.showQuickContact()ImageView 或其他一些视图元素时,我希望在其中显示快速联系对话框>。由于某种原因,每次我尝试 Eclair 时,都会抛出以下错误:

01-02 17:51:28.869: 错误/AndroidRuntime(657): java.lang.RuntimeException:无法启动活动 组件信息{com.sx.favwidget/com.sx.favwidget.PopupActivity}: android.content.ActivityNotFoundException:找不到要处理的活动 意图 { act=com.android.contacts.action.QUICK_CONTACT dat=content://com.android.contacts/contacts/lookup/0n4D29415739 flg=0x14200000(有额外内容)

(我省略了 logcat 的其余部分,但如果你们需要的话我可以把它放回去)

当我在 Froyo 上尝试完全相同的代码时,它就可以工作了。我不想让我的应用程序仅针对 Froyo 用户 - 我的目标是 2.1 作为最低操作系统级别。我发现 Stack Overflow 上的其他一些人在显示 QuickContacts 方面遇到了困难。

我可以使用 QuickContactBadge,这在 Eclair 上确实有效,但我不允许在 AppWidget 中使用 QuickContactBadge,所以我改为这样做。我深入研究了 Android 的源代码,找到了相关的 XML 文件和用于创建布局的代码,但我无法轻松地自己编译它,因为所有私有 API 调用都令人头疼。

这是我的代码。这很简单。

grid.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

        String name = ((TextView)v.findViewById(R.id.grid_item_label)).getText().toString();

        Cursor sc = getContentResolver().query(Contacts.CONTENT_URI, new String[] {Contacts.LOOKUP_KEY,   Contacts._ID}, Contacts.DISPLAY_NAME + "= ?", new String[] {name}, null);

        sc.moveToFirst();          

        String lookup_key = sc.getString(sc.getColumnIndex(Contacts.LOOKUP_KEY));

        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookup_key);

        QuickContact.showQuickContact(getApplicationContext(), v, uri, QuickContact.MODE_SMALL, null);

        }
}

奇怪的是它适用于 Froyo,而不是 Eclair,但 API 调用从 Android 2.0 起就已经存在了。有人可以帮我吗?

非常感谢!!!

I've done a lot of googling over the days and I haven't been able to get this problem solved. I'm writing an app and a widget in which I want the quick contact dialog displayed when the user clicks on an ImageView or some other view element by calling QuickContact.showQuickContact(). For some reason, every time I try on Eclair, I get the following error thrown:

01-02 17:51:28.869: ERROR/AndroidRuntime(657):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.sx.favwidget/com.sx.favwidget.PopupActivity}:
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=com.android.contacts.action.QUICK_CONTACT
dat=content://com.android.contacts/contacts/lookup/0n4D29415739
flg=0x14200000 (has extras)

(I left out the rest of the logcat, but I can put it back if you guys need it)

When I try the exact same code on Froyo, it just works. I don't want to have my app targeted only for Froyo users - I'm targeting 2.1 as the minimum OS level. I've found some other people on Stack Overflow struggling with getting QuickContacts to display.

I could use a QuickContactBadge, and that does work on Eclair, but I'm not allowed a QuickContactBadge in an AppWidget, so I have do this instead. I dug through Android's source code and found the relevant XML files and code for creating the layout but I can't just easily compile it myself because it's a huge headache with all the private API calls.

Here is my code. It's simple.

grid.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

        String name = ((TextView)v.findViewById(R.id.grid_item_label)).getText().toString();

        Cursor sc = getContentResolver().query(Contacts.CONTENT_URI, new String[] {Contacts.LOOKUP_KEY,   Contacts._ID}, Contacts.DISPLAY_NAME + "= ?", new String[] {name}, null);

        sc.moveToFirst();          

        String lookup_key = sc.getString(sc.getColumnIndex(Contacts.LOOKUP_KEY));

        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookup_key);

        QuickContact.showQuickContact(getApplicationContext(), v, uri, QuickContact.MODE_SMALL, null);

        }
}

It's just so strange that it works on Froyo, not Eclair, but the API call has been there since Android 2.0. Can anyone help me here??

Thanks so much!!!

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

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

发布评论

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

评论(1

锦上情书 2024-10-16 17:55:55

我前段时间也解决了这个问题,但忘了发布如何解决。我所做的是启动一个透明的新活动,并且我得到了启动意图的矩形。该活动只有一个 QuickContactBadge 元素,因此我使用矩形定位它并自动对其执行单击操作。一旦显示出来,我就完成了活动 - 但徽章仍然存在。因此,当用户单击 QuickContactBadge 时,他们会立即返回到开始的位置。

我没有机会彻底阅读你的(Omegamon)代码 - 你的方法和我的相似吗?

I solved this as well some time ago but forgot to post how. What I did was launch a new activity that was transparent, and I got the rectangle from which the intent was launched. This activity had only a QuickContactBadge element, so I positioned it using the rectangle and performed a click action automatically on it. Once this was displayed, I finished the activity - but the badge remains. Therefore, when the person clicked out of the QuickContactBadge, they'd be right back to where they started.

I didn't get a chance to peruse your (Omegamon) code thoroughly - is your method similar to mine?

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