Android - 显示具有相同电话号码的联系人列表
我有一个小部件,可以通过电话号码打开联系人列表。我正在使用Contacts.Intents.SHOW_OR_CREATE_CONTACT 我知道它已被弃用,但我希望它可以在 android 1.6 上运行。我有一个电话号码可用于查找意图。这是代码
Intent contViewIntent = new Intent(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
contViewIntent.setData(Uri.fromParts("tel", number, null));
PendingIntent contPendIntent = PendingIntent.getActivity(context, 0, contViewIntent, 0);
views.setOnClickPendingIntent(viewID, contPendIntent);
当联系人列表有 2 个或更多具有相同号码的联系人时,这将打开联系人列表并让用户选择一个。这在 1.6 上工作正常,但在 2.0 及更高版本上,它会显示姓名中仅包含数字 1 或数字 2 的联系人列表,当您从列表中选择其中一个来查看时,您会收到错误。
04-09 19:12:47.891: 错误/CursorWindow(105):错误的请求 对于字段槽 0,6。行数 = 2, 列数 = 6
04-09 19:12:47.992: 错误/Android运行时(105): java.lang.IllegalStateException:获取 第 0 行第 6 列的字段槽失败
如何让它在上面的 1.6 和 2.0 上工作?
I have a widget that will open the contacts list by a phone number. I am using Contacts.Intents.SHOW_OR_CREATE_CONTACT
I know it's deprecated but I want this to work on android 1.6. I have a phone number to use on the lookup intent. here is the code
Intent contViewIntent = new Intent(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
contViewIntent.setData(Uri.fromParts("tel", number, null));
PendingIntent contPendIntent = PendingIntent.getActivity(context, 0, contViewIntent, 0);
views.setOnClickPendingIntent(viewID, contPendIntent);
When the Contact list has 2 or more contacts with the same number then this will open the list of contacts and has the user select one. This works fine on 1.6, but on 2.0 and above it shows a list of contacts with just the number 1 or number 2 in the names and when you select one of those from the list to view you get an error.
04-09 19:12:47.891:
ERROR/CursorWindow(105): Bad request
for field slot 0,6. numRows = 2,
numColumns = 604-09 19:12:47.992:
ERROR/AndroidRuntime(105):
java.lang.IllegalStateException: get
field slot from row 0 col 6 failed
how do I get this to work on 1.6 and 2.0 above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 2.0 有一个全新 API 用于管理联系人(查找 ContactsContract)。在我的应用程序中,我最终编写了两次低级联系人管理 - 一次用于 2.0,一次用于 1.6 及以下(我通过反射检查 ContactsContract 类是否存在,并在这种情况下切换到 2.0+ 代码)。
Android 2.0 has a completely new API for managing contacts (look up ContactsContract). In my app, I ended up writing the low-level contact management twice - once for 2.0, once for 1.6 and under (I check via reflection to see if the ContactsContract class exists and switch to the 2.0+ code in that case).
我认为您可能更好地将 Android 内容提供程序 api 与 SQL 查询结合使用(查找与电话号码匹配的行):
http://developer.android.com/guide/topics/providers/content-providers.html
然后您可以显示一个选项屏幕,要求用户选择哪个如果查询返回两个联系人,则 contact 是合适的。
然后,您可以将 _id 字段(唯一)传递给联系人应用程序以打开所选联系人(避免您看到的错误)。
I think you may be better using the Android content provider api in combination with a SQL query (find row or rows with telephone number match):
http://developer.android.com/guide/topics/providers/content-providers.html
Then you can show a option screen asking user to select which contact is appropriate if the query returns two contacts.
Then you can pass the _id field (which is unique) to the contacts app to open the selected contact (avoiding the error you see).