android contacts provider: how to set phone number primary

眉间皱痕 提交于 2019-12-23 17:15:59

问题


How to set a contact's phone number to be primary number when adding or updating a contact building a custom contacts provider. The adding and updating of contacts is working fine but I don't know how to set one number of the contact to be primary, or default number.


回答1:


mValues.put(Phone.IS_PRIMARY, 1);
mValues.put(Phone.IS_SUPER_PRIMARY, 1);

Both Phone.IS_PRIMARY and Phone.IS_SUPER_PRIMARY have to be set.




回答2:


I had the same problem, my solution is:

ContentProviderOperation.Builder bld = ContentProviderOperation.newUpdate(Uri.withAppendedPath(ContactsContract.Data.CONTENT_URI, myRawIdOfNumber ));
bld = bld.withValue( ContactsContract.CommonDataKinds.Phone.IS_PRIMARY, new Integer(1) );
bld = bld.withValue( ContactsContract.CommonDataKinds.Phone.IS_SUPER_PRIMARY, new Integer(1) );
ops.add( bld.build() );
try { getContentResolver().applyBatch( ContactsContract.AUTHORITY, ops ); } catch ...


来源:https://stackoverflow.com/questions/14424407/android-contacts-provider-how-to-set-phone-number-primary

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