所以我试图在android studio中创建一个按钮,它会在发送短信时打开一个看起来像联系人选择的联系人选择框(允许选择多个联系人,让你选择联系人组)。
我已尝试过此代码,但只允许您选择一个联系人:
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);
}
用户选择联系人后,我将如何获取信息?
作为@Allu我没有找到一种方法,我不必自己设计这一切。 最后我写了这段代码来获取组并使用ListView将它们显示给用户:
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;
}