Note that there are some explanatory texts on larger screens.

plurals
  1. POFetch Contacts in android application
    primarykey
    data
    text
    <p>I was following these links to get the contacts in my application </p> <p><a href="https://stackoverflow.com/questions/866769/how-to-call-android-contacts-list">How to call Android contacts list?</a></p> <p><a href="http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/" rel="nofollow noreferrer">http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/</a></p> <p>I can display the list of contacts on phone but </p> <p>-</p> <ol> <li><p>I want to add a checkbox at each contact so that user can select multiple contacts and by clicking the done button he should be able to get all the contacts he selected</p></li> <li><p>Also I want to get the name of contact as well as the phone number of contact , see my code :</p></li> </ol> <pre> if (resultCode == Activity.RESULT_OK) { Uri contactData = data.getData(); Cursor c = managedQuery(contactData, null, null, null, null); if (c.moveToFirst()) { String name = c.getString(c .getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); String number = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.HAS_PHONE_NUMBER)); Log.v("name", name +" "+number); // TODO Whatever you want to do with the selected contact // name. } } </pre> <p>on log cat it shows output as :</p> <pre><code>01-09 12:46:41.688: V/name(699): Xyz 1 </code></pre> <p>that is the name of contact is xyz and it has atleast 1 phone number associated with it.Please help me on how can i get the number associated with that contact.</p> <p><strong>EDIT :</strong></p> <p>if i use this(<code>String number = c.getString(c.getColumnIndexOrThrow(People.NUMBER));</code>) line in code the I get following exception :</p> <pre><code>01-09 13:33:23.008: E/AndroidRuntime(786): FATAL EXCEPTION: main 01-09 13:33:23.008: E/AndroidRuntime(786): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/0r1-2C2E30/1 (has extras) }} to activity {sra.com/sra.com.ContactsDemo}: java.lang.IllegalArgumentException: column 'number' does not exist 01-09 13:33:23.008: E/AndroidRuntime(786): at android.app.ActivityThread.deliverResults(ActivityThread.java:3515) 01-09 13:33:23.008: E/AndroidRuntime(786): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557) 01-09 13:33:23.008: E/AndroidRuntime(786): at android.app.ActivityThread.access$2800(ActivityThread.java:125) 01-09 13:33:23.008: E/AndroidRuntime(786): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063) 01-09 13:33:23.008: E/AndroidRuntime(786): at android.os.Handler.dispatchMessage(Handler.java:99) 01-09 13:33:23.008: E/AndroidRuntime(786): at android.os.Looper.loop(Looper.java:123) 01-09 13:33:23.008: E/AndroidRuntime(786): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-09 13:33:23.008: E/AndroidRuntime(786): at java.lang.reflect.Method.invokeNative(Native Method) 01-09 13:33:23.008: E/AndroidRuntime(786): at java.lang.reflect.Method.invoke(Method.java:521) 01-09 13:33:23.008: E/AndroidRuntime(786): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-09 13:33:23.008: E/AndroidRuntime(786): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-09 13:33:23.008: E/AndroidRuntime(786): at dalvik.system.NativeStart.main(Native Method) 01-09 13:33:23.008: E/AndroidRuntime(786): Caused by: java.lang.IllegalArgumentException: column 'number' does not exist 01-09 13:33:23.008: E/AndroidRuntime(786): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314) 01-09 13:33:23.008: E/AndroidRuntime(786): at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99) 01-09 13:33:23.008: E/AndroidRuntime(786): at sra.com.ContactsDemo.onActivityResult(ContactsDemo.java:49) 01-09 13:33:23.008: E/AndroidRuntime(786): at android.app.Activity.dispatchActivityResult(Activity.java:3890) 01-09 13:33:23.008: E/AndroidRuntime(786): at android.app.ActivityThread.deliverResults(ActivityThread.java:3511) 01-09 13:33:23.008: E/AndroidRuntime(786): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload