问题
Is there way to programmatically adds the contact to the internal phone contacts book as a "phone contact"?
I've tried:
list.add(ContentProviderOperation
.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
.build());
with this parameters contact successfully saves to the phone, but in case i set up filter to "display phone contacts only" - created contact not appears. btw, i've read that contacts with null
type can be loses drying accounts synchronization (haven't remember the full case)
then i tried to retrieve ACCOUNT_TYPE
and ACCOUNT_NAME
from existing phone contact and gets Phone
and Local Phone Account
strings, but when i tried to save contact with same parameters:
list.add(ContentProviderOperation
.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, "Phone")
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, "Local Phone Account")
.build());
the result was the same to the first case with null
type.
is there any constants (or it should be another way) to save data like "phone contact"?
回答1:
The "phone only
" account is not fully supported by plain Android
, it's usually added (or unlocked) by device makers.
Here are the ones I know of, feel free to add more in case you find more.
The format is <maker>
: ACCOUNT_TYPE
, ACCOUNT_NAME
- samsung: "vnd.sec.contact.phone: "vnd.sec.contact.phone"
- htc: "com.htc.android.pcsc: "pcsc"
- sony: "com.sonyericsson.localcontacts: "Phone contacts"
- lge: "com.lge.sync: "Phone"
- lge (option 2): "com.lge.phone"
- t-mobile: "vnd.tmobileus.contact.phone: "MobileLife Contacts"
- huawei: "com.android.huawei.phone: "Phone"
- lenovo: "Local Phone Account: "Phone"
来源:https://stackoverflow.com/questions/44799397/save-contacts-as-phone-contact