Set SEND_TO_VOICEMAIL on Android contacts

别说谁变了你拦得住时间么 提交于 2019-12-22 09:46:30

问题


I'm trying to modify the value of SEND_TO_VOICEMAIL from 0 to 1 and vice versa. I succeed to modify the others contact's details, such as name, number, nickname, email, ecc... but I need to change SEND_TO_VOICEMAIL.

I tried many possibility, but this should work... i guess:

        String rawContactId = "1";

        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        ops.add(
            ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
            .withSelection( Data.RAW_CONTACT_ID + "=?" , new String[] { rawContactId })
            .withValue(ContactsContract.RawContacts.SEND_TO_VOICEMAIL , 1)
            .build()
        );

        try {
            getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (OperationApplicationException e) {
            e.printStackTrace();
        }

but the logcat says:

ERROR/AndroidRuntime(822): android.database.sqlite.SQLiteException: no such column: send_to_voicemail: , while compiling: UPDATE data SET send_to_voicemail=? WHERE _id =?

I really don't know what to try anymore. Any help would be really appreciated. Thanks.


回答1:


According to the[manual, the SEND_TO_VOICEMAIL field you're looking for isn't in the ContactsContract.Data table but in the ContactsContract.Contacts table. It seems like you're trying to modify the wrong table.

See ContactsContract.Data and ContactsContract.Contacts for the fields in each table.




回答2:


It is better modify through ContentProvider Contacts.CONTENT_URI:

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newUpdate(Contacts.CONTENT_URI)
    .withSelection(Contacts._ID + "=?", new String[]{hmout.get("cid").toString()})
    .withValue(Contacts.SEND_TO_VOICEMAIL, 1)
    .build());

try { 
    getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) { 
    Log.e("Exception: ", e.getMessage()); 
}


来源:https://stackoverflow.com/questions/7298767/set-send-to-voicemail-on-android-contacts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!