我正在尝试打开联系意图并让用户选择多重联系人意图调用:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); // Show user only contacts / phone numbersstartActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
使用这种方法,用户只能选择一个联系人.我怎样才能让他选择很多联系人然后获得他选择的所有号码?
解决方法:
有两个是这样做的!
1.设定意图的最大选择限制:
public static final int REQUEST_CODE_PICK_CONTACT = 1;public static final int MAX_PICK_CONTACT= 10;private voID launchMultiplePhonePicker() { Intent phonebookIntent = new Intent("intent.action.INteraCTION_topMENU"); phonebookIntent.putExtra("additional", "phone-multi"); phonebookIntent.putExtra("maxRecipIEntCount", MAX_PICK_CONTACT); phonebookIntent.putExtra("FromMMS", true); startActivityForResult(phonebookIntent, REQUEST_CODE_PICK_CONTACT); }@OverrIDepublic voID onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESulT_OK) { if(requestCode == REQUEST_CODE_PICK_CONTACT) { Bundle bundle = data.getExtras(); String result= bundle.getString("result"); ArrayList<String> contacts = bundle.getStringArrayList("result"); Log.i(TAG, "launchMultiplePhonePicker bundle.toString()= " + contactsPick.toString() ); } } super.onActivityResult(requestCode, resultCode, data);}
注意:在每个 *** 作系统版本和设备上可能会有所不同,并且可能不适用于所有 *** 作系统版本和设备.
要么
>这样做:
以编程方式读取联系人并在活动中的ListVIEw中显示它们,然后使用ListVIEw项目中的复选框并允许选择多个项目.
例如如何读取系统联系人:
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null); while (cursor.movetoNext()) { String contactID = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.disPLAY_name)); if("1".equals(hasPhone) || Boolean.parseBoolean(hasPhone)) { // You kNow it has a number so Now query it like this Cursor phones = myActivity.getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactID, null, null); while (phones.movetoNext()) { String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); int itype = phones.getInt(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)); final boolean isMobile = itype == ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE || itype == ContactsContract.CommonDataKinds.Phone.TYPE_WORK_MOBILE; // Do something here with 'phoneNumber' such as saving into // the List or Array that will be used in your 'ListVIEw'. } phones.close(); }}
总结 以上是内存溢出为你收集整理的android – 多个选择联系意图全部内容,希望文章能够帮你解决android – 多个选择联系意图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)