1

I am working on my app in which user will select and saves the contacts (3 contacts) from phonebook and sends them SMS with a click of a button . I am done with searching on that sms and button part, all i want to know what things will it require for taking the contacts input and saving them. I'm not expecting any full fledged programming from someone just the breif details on which i can search upon. I am only some months old for android. Thanks in advance

bhanu kaushik
  • 391
  • 1
  • 7
  • 30

1 Answers1

0

try this, use-

Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);

then, in your onAcitivityResult:

Uri contact = data.getData();
      ContentResolver cr = getContentResolver();

    Cursor c = managedQuery(contact, null, null, null, null);
    //      c.moveToFirst();


    while(c.moveToNext()){
        String id = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));

        String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        if (Integer.parseInt(c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
            Cursor pCur = cr.query(Phone.CONTENT_URI,null,Phone.CONTACT_ID +" = ?", new String[]{id}, null);

            while(pCur.moveToNext()){
                String phone = pCur.getString(pCur.getColumnIndex(Phone.NUMBER));
                textview.setText(name+" Added " + phone);
            }
        }
}

You can also check this link for more help- How to call Android contacts list?

Community
  • 1
  • 1
amit singh
  • 1,407
  • 2
  • 16
  • 25