1

我正在尝试开发一个应用程序,在该应用程序中,我需要将所有呼叫自动发送到语音信箱,除了一些我将其 ID 存储在我的应用程序的不同表中的白名单联系人。有人可以建议我这样做的正确方法吗?

4

1 回答 1

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

您可以在此字符串缓冲区中收集白名单的 ID,将 contentValues 设置为 contentValues.put(Contacts.SEND_TO_VOICEMAIL, 1) 并将我的代码更改为 NOT IN (

于 2013-09-13T12:08:15.487 回答