So i'm trying to create a button in android studio that will open a contacts selection box that looks like the contacts selection when sending S.M.S (allow to choose more than one contact, letting you choose groups of contacts).
i have tried this code, but it only letting you choose one contact:
private static final int CONTACT_PICKER_RESULT = 1001; public void doLaunchContactPicker(View view) { Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI); startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT); }
after the user will select the contacts, how will i get the info?
update:
as @Allu i didn't find a way that i wont have to design this all by myself. eventually i wrote this code to get the groups and used ListView to display them to the users:
public class myGroup {
private String _ID;
private String _TITLE;
private ArrayList<String> _PHONE_NUMBERS;
public myGroup(String id, String title){
_ID = id;
_TITLE = title;
//get the contacts phone numbers
//_PHONE_NUMBERS.add();
}
}
private ArrayList<myGroup> getGroups(){
ArrayList<myGroup> myGroups = new ArrayList<myGroup>();
Cursor cursor =getContentResolver().query(ContactsContract.Groups.CONTENT_URI,new String[]{ContactsContract.Groups._ID, ContactsContract.Groups.TITLE}, null, null, null);
cursor.moveToFirst();
int len = cursor.getCount();
String[] a = cursor.getColumnNames();
for(int i = 0; i < len; i++){
if(cursor.getColumnIndex(ContactsContract.Groups.DELETED) == 1){
continue;
}
myGroups.add(new myGroup(cursor.getString(cursor.getColumnIndex(Groups._ID)),
cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.TITLE))));
cursor.moveToNext();
}
return myGroups;
}