我正在尝试开发一个应用程序,我需要将所有呼叫自动发送到语音邮件,除了一些白名单联系人,其ID我存储在我的应用程序的不同表中。有人可以建议我这样做的正确方法。
答案 0 :(得分:0)
这是我已经穿过的代码,我可以在其中选择列表中的联系人,以便将这些联系人的所有呼叫直接定向到邮箱,或者不定向到邮箱。
StringBuilder mailboxIds = new StringBuilder(""); // a stringbuilder that collects the id of the checked contacts in the list
int visibleItemCount = contactAdapter.getCount();
for (int i = 0; i < visibleItemCount; i++) { // iterating the visible and checked contacts of the list
ContactItem contactItem = contactAdapter.getItem(i);
if (contactItem.isChecked()) {
mailboxIds.append(contactItem.getId() + ","); // creating a coma-seperated string with the ideas for the later query
}
}
mailboxIds.replace(mailboxIds.length() - 1, mailboxIds.length(), ""); // removing the last coma from the list
ContentResolver contentResolver = getActivity().getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues = new ContentValues();
if(toMailbox){ // if all selected contacts should go to the mailbox
contentValues.put(Contacts.SEND_TO_VOICEMAIL, 1);
}else{ // if all selected contacts should not go to the mailbox
contentValues.put(Contacts.SEND_TO_VOICEMAIL, 0);
}
contentResolver.update(Contacts.CONTENT_URI, contentValues, BaseColumns._ID + " IN (" + mailboxIds + ")", null); // updating all contacs of the selected ids
您可以在此stringbuffer中收集白名单的ID,将contentValues设置为contentValues.put(Contacts.SEND_TO_VOICEMAIL,1)并将我的代码更改为NOT IN(