我在製作短信應用程序,並且想要訪問我的Android應用程序 中的聯繫人。如何訪問我的Android程序中的聯繫人
我想訪問聯繫人,就好像他們在實際聯繫人列表中的位置一樣。選擇時,我需要返回到我可以發送短信給該人的活動。還是有可能訪問存儲聯繫人的數據庫?
我的代碼如下所示:
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
String no = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
我logcat的是這樣的:
09-07 12:46:15.458: DEBUG/AndroidRuntime(473): Shutting down VM
09-07 12:46:15.458: WARN/dalvikvm(473): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): FATAL EXCEPTION: main
09-07 12:46:15.478: ERROR/AndroidRuntime(473): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/0r1-512D3F3D533B/1 flg=0x1 (has extras) }} to activity {task.list/task.list.Msgactivity}: java.lang.IllegalArgumentException: column 'data1' does not exist
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.app.ActivityThread.access$2000(ActivityThread.java:117)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.os.Handler.dispatchMessage(Handler.java:99)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.os.Looper.loop(Looper.java:123)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at java.lang.reflect.Method.invoke(Method.java:507)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at dalvik.system.NativeStart.main(Native Method)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): Caused by: java.lang.IllegalArgumentException: column 'data1' does not exist
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at task.list.Msgactivity.onActivityResult(Msgactivity.java:99)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
09-07 12:46:15.478: ERROR/AndroidRuntime(473): ... 11 more
09-07 12:46:15.489: WARN/ActivityManager(61): Force finishing activity task.list/.Msgactivity
誰能幫助我?
我是否必須添加權限 – sajith
你需要添加權限。 –