Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
865 views
in Technique[技术] by (71.8m points)

android - Save Contacts as "Phone contact"

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"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  1. samsung: "vnd.sec.contact.phone: "vnd.sec.contact.phone"
  2. htc: "com.htc.android.pcsc: "pcsc"
  3. sony: "com.sonyericsson.localcontacts: "Phone contacts"
  4. lge: "com.lge.sync: "Phone"
  5. lge (option 2): "com.lge.phone"
  6. t-mobile: "vnd.tmobileus.contact.phone: "MobileLife Contacts"
  7. huawei: "com.android.huawei.phone: "Phone"
  8. lenovo: "Local Phone Account: "Phone"
  9. xiaomi: "com.xiaomi"
  10. oppo: "com.oppo.contacts.device"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...