Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to read contact in android
    primarykey
    data
    text
    <p>i am developing an android sms app in which i want to read contact number from contacts using following code </p> <pre><code> Intent ContactPickerIntent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI); ContactPickerIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); startActivityForResult(ContactPickerIntent, CONTACT_PICKER_RESULT); </code></pre> <p>it is working fine on emulator but not on device. what changes should i make to make it run on the device. </p> <p>here is my onactivityresult function</p> <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { switch (requestCode) { case CONTACT_PICKER_RESULT: Cursor cursor=null; try { Uri result = data.getData(); Log.v(DEBUG_TAG, "Got a contact result: " + result.toString()); // get the contact id from the Uri String id = result.getLastPathSegment(); // query for everything contact number cursor = getContentResolver().query( Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[]{id}, null); cursor.moveToFirst(); int phoneIdx = cursor.getColumnIndex(Phone.NUMBER); if (cursor.moveToFirst()) { phonenofromcontact = cursor.getString(phoneIdx); finallistofnumberstosendmsg +=","+phonenofromcontact; Log.v(DEBUG_TAG, "Got phone no : " + phonenofromcontact); } else { Log.w(DEBUG_TAG, "No results"); } } catch(Exception e) { Log.e(DEBUG_TAG, "Failed to get contact number", e); } finally { if (cursor != null) { cursor.close(); } } phonePhoneno= (EditText)findViewById(R.id.phonenofromcontact); phonePhoneno.setText(finallistofnumberstosendmsg); //phonePhoneno.setText(phonenofromcontact); if(phonenofromcontact.length()==0) { Toast.makeText(this, "No contact number found for this contact", Toast.LENGTH_LONG).show(); } break; } } else { Log.w(DEBUG_TAG, "Warning: activity result not ok"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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