How to properly set an android intent with the SHOW_OR_CREATE_CONTACT action?

不打扰是莪最后的温柔 提交于 2020-01-24 20:12:07

问题


I would like to use the internal Contact activity to create a new Contact. Here is the code:

        Intent i = new Intent();
    i.setAction(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    i.setData(Uri.fromParts("tel", "12345678", null));
    i.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true);
    i.putExtra(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_WORK); 
    i.putExtra(ContactsContract.Intents.Insert.EMAIL, "naoknaoknaok@gmail.com");
    i.putExtra(ContactsContract.CommonDataKinds.Email.TYPE, ContactsContract.CommonDataKinds.Email.TYPE_WORK);
    i.putExtra(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, "Ide");
    i.putExtra(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, "Vele");
    i.putExtra(ContactsContract.CommonDataKinds.Organization.COMPANY, "Company name");
    i.putExtra(ContactsContract.CommonDataKinds.Organization.TYPE, ContactsContract.CommonDataKinds.Organization.TYPE_WORK);
    i.putExtra(ContactsContract.CommonDataKinds.Organization.LABEL, "label");
    i.putExtra(ContactsContract.CommonDataKinds.Organization.TITLE, "job title");
    i.putExtra(ContactsContract.CommonDataKinds.Organization.DEPARTMENT, "department");
    i.putExtra(ContactsContract.CommonDataKinds.Organization.JOB_DESCRIPTION, "job description");
    i.putExtra(ContactsContract.CommonDataKinds.Organization.SYMBOL, "symbol");
    i.putExtra(ContactsContract.CommonDataKinds.Organization.OFFICE_LOCATION, "office location");

But this code only partially works. Only the phone number and the email address are visible in the activity, the other fields are unset.

Here is the screenshot from the emulator: edit_contact1

Sorry for not including it, but i don't have enough reputation to include images.

Any help would be greatly appreciated !

Some update: the following code sets the 'Given name' field:

i.putExtra(ContactsContract.Intents.Insert.NAME, "simple name");

回答1:


i'd imagine that only the constant keys in ContactsContract.Intents.Insert.* are understood by the intent receiver. that would make sense.



来源:https://stackoverflow.com/questions/3456319/how-to-properly-set-an-android-intent-with-the-show-or-create-contact-action

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