get contact info from android contact picker -


I am trying to call the contact picker, get people name, phone and e-mail in the wire and Another activity, using an intention to send them, is yet to work:

  intended intent = new intent (Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); StartActivityForResult (intent, 1); // ... @Override Public Zero onActivityResult (integer reqCode, integer resultCode, intent data) {super.onActivityResult (reqCode, resultCode, data); If (resultCode == activity. RESULT_OK) {Ure contact data = data .getData (); Cursor c = managed query (contact data, empty, null, empty, zero); If (c.moveToFirst ()) {string name = c.getstring (c.getColumnIndexOrThrow (contactContract.Contacts.DISPLAY_NAME)); Intent intention = new intent (current activity. This, new activity class); Intent.putExtra ("name", name); StartActivityForResult (intent, 0); }}}  

But if I add to:

  string number = c.getString (c.getColumnIndexOrThrow (ContactsContract.CommonDataKinds.Phone.NUMBER)) ;  

This force closes

Perhaps there is another way to get their number?

phone number

phone number self table And should be asked for separate inquiries Use the stored URI in the SDK variable contacts to query the phone number table. CommonDayind phone. CONTRAINSURI Use a WHERE conditional to get a phone number for the specified contact.

  if (integer.parseInt (cur.getString (cur.getColumnIndex (ContactsContract.Contacts.HAS_PHONE_NUMBER))) gt; {cursor pCur = cr.query (ContactsContract.CommonDataKinds.Phone CONTENT_URI, Faucet, ContactCractract.comCommentIndones.ContactsAdid + "=?", New string [] {ID}, blank); While (pCur.moveToNext ()) {// Do something with the phone} pCur.close (); }  

A second query against the Android contact SQLite database, the phone number is inquired about the URI stored in the contact's content. CommonDayind phone. Contransurai Contact ID is stored in the phone table as ContactsContract.CommonDataKinds.Phone.CONTACT_ID and used to limit where the volume data is not given.

Email Address

Asking for an email address is similar to phone numbers, a query should be made to get email addresses from the database. Check the stored URI in contact communication. CommonDayind E-mail. Asked CONTENT_URI email address table.

  Cursor emailCur = cr.query (ContactsContract.CommonDataKinds.Email.CONTENT_URI, Null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + "=?", New String [] {ID}, Faucet) ; While (emailCur.moveToNext ()) {// This will allow you to get multiple email addresses / If email addresses stored in an array string email = emailCur.getString (emailCur.getColumnIndex (ContactsContract.CommonDataKinds.Email.DATA) it was done) ; String Email Type = EmailGradeGrid String (emailCur.getColumnIndex (ContactsContract.CommonDataKinds.Email.TYPE)); } EmailCur.close ();  

Field names for email tables along with phone queries are also stored under ContactsContract.CommonDataKinds. The email query is done at the URI in ContactsContract.CommonDataKinds.Email.CONTENT_URI and the field should match the contactContract.CommonDataKinds.Email.CONTACT_ID field. Since many email addresses can be deposited in the loop through the returned record in the cursor.

More Tutorials

This method requires Android API version 5 or higher.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -