开发者

How to display a contact in Android

//Look up a contact by phone number and display it.

Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
intent.setData(Uri.fromParts("tel", vc.cellphone, null));
startActivity(intent);

This code works as intended. However, if there is more than one contact with that number, we get a crash. When the crash happens. Logcat says:

04-04 05:26:34.764: INFO/ActivityManager(60): Starting activity: Intent { act=com.android.contacts.action.SHOW_OR_CREATE_CONTACT dat=tel:078551212 cmp=com.android.contacts/.ui.ShowOrCreateActivity }
04-04 05:26:35.834: INFO/ActivityManager(60): Starting activity: Intent { act=android.intent.action.SEARCH cmp=com.android.contacts/.ContactsListActivity (has extras) }
04-04 05:26:36.064: INFO/ContactsListActivity(276): Called with action: android.intent.action.SEARCH
04-04 05:26:36.804: INFO/ActivityManager(60): Displayed activity com.android.contacts/.ui.ShowOrCreateActivity: 1999 ms (total 1999 ms)
04-04 05:26:36.814: INFO/ActivityManager(60): Displayed activity com.android.contacts/.ContactsListActivity: 858 ms (total 858 ms)
04-04 05:26:43.153: ERROR开发者_运维问答/CursorWindow(276): Bad request for field slot 0,6. numRows = 2, numColumns = 6
04-04 05:26:43.173: DEBUG/AndroidRuntime(276): Shutting down VM
04-04 05:26:43.173: WARN/dalvikvm(276): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-04 05:26:43.183: ERROR/AndroidRuntime(276): Uncaught handler: thread main exiting due to uncaught exception
04-04 05:26:43.223: ERROR/AndroidRuntime(276): java.lang.IllegalStateException: get field slot from row 0 col 6 failed
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.database.CursorWindow.getString_native(Native Method)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.database.CursorWindow.getString(CursorWindow.java:329)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.database.CursorWrapper.getString(CursorWrapper.java:135)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at com.android.contacts.ContactsListActivity.getContactUri(ContactsListActivity.java:1564)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at com.android.contacts.ContactsListActivity.getSelectedUri(ContactsListActivity.java:1598)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at com.android.contacts.ContactsListActivity.onListItemClick(ContactsListActivity.java:1255)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.app.ListActivity$2.onItemClick(ListActivity.java:312)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.widget.ListView.performItemClick(ListView.java:3285)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.os.Handler.handleCallback(Handler.java:587)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.os.Looper.loop(Looper.java:123)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at android.app.ActivityThread.main(ActivityThread.java:4363)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at java.lang.reflect.Method.invokeNative(Native Method)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at java.lang.reflect.Method.invoke(Method.java:521)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-04 05:26:43.223: ERROR/AndroidRuntime(276):     at dalvik.system.NativeStart.main(Native Method)


After the question updates, most of this answer became irrelevant, but the links may still be useful for others having issues with the contacts, so instead of deleting the answer, I decided to keep those:


Links to Q&A in SO:

How can I launch the 'Add Contact' activity in android

How to call Android contacts list?

Launching external application from my app

This one deals with exactly your problem: Android - Show list of contacts with same phone number . There is an answer there by DEzra suggesting to use "Android content provider api in combination with a SQL query"


Links to the android API:

http://developer.android.com/reference/android/content/Intent.html

http://developer.android.com/reference/android/provider/ContactsContract.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜