I have one question. In my application I open the phonebook and pull out the name and number of the person you have chosen. Here is the code that I do:
public void showContactsChooser(){
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 1001);
}
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data){
super.onActivityResult(reqCode, resultCode, data);
switch(reqCode){
case (1001):
if (resultCode == Activity.RESULT_OK){
ContentResolver cr = getContentResolver();
Uri contactData = data.getData();
Cursor c = cr.query(contactData, null, null, null, null);
String phone = "";
if (c.moveToFirst()){
String name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
"DISPLAY_NAME = '" + name + "'", null, null);
if (cursor.moveToFirst()) {
String contactId =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
//
// Get all phone numbers.
//
Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null);
while (phones.moveToNext()) {
phone = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
int type = phones.getInt(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
switch (type) {
case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
break;
}
}
phones.close();
Toast.makeText(getApplicationContext(), name + " " + phone, Toast.LENGTH_SHORT).show();
Log.d("PICK", "Contact " + name + " " + phone);
}
}
}
}
}
In this piece of code I open the phone book and when you click on a contact name and get a phone number, then go back to the old Activiti. But I can only choose one person. And I need to choose a few. My question:
Can I choose a few people in the phone book and then pass them to the application. And how to do it?