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
Asked
Active
Viewed 215 times
1
-
i haven't written any code for this, because i have no idea from where to start for taking contacts to saving them... do i have to import the contacts API for this ?? – bhanu kaushik Jan 18 '14 at 05:22
-
first, google about it. and try yourself than ask here. – Sagar Maiyad Jan 18 '14 at 05:24
-
that what i am asking sir, what to google for ??? what wanted the terms involved for developing this ... anyways thanks – bhanu kaushik Jan 18 '14 at 05:27
1 Answers
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
-
do i have to declare REAS_CONTACTS permission also in the Manifest ?? – bhanu kaushik Jan 18 '14 at 06:21
-
@user3205379 yes mate and if it helps you then you can accept it as answer. If you have any problm, then let me know. – amit singh Jan 18 '14 at 06:23