1

I call an intent to add a contact to device like this :

                    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
                    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
                    intent.putExtra(ContactsContract.Intents.Insert.NAME,
                            user.getName());
                    intent.putExtra(ContactsContract.Intents.Insert.IM_HANDLE,
                            user.getID());
                    intent.putExtra(
                            ContactsContract.Intents.Insert.IM_PROTOCOL,
                            ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM);
                    startActivityForResult(intent, 0);

The documentation says:

public static final String PROTOCOL
This column should be populated with one of the defined constants, e.g. PROTOCOL_YAHOO. If the value of this column is PROTOCOL_CUSTOM, the CUSTOM_PROTOCOL should contain the name of the custom protocol. Constant Value: "data5".

When I click to add or edit contact a pop-up dialog appear with empty edittext where I have to select the name of CUSTOM_PROTOCOL. According to the docs I cant find the way how to set CUSTOM_PROTOCOL value.

Matej Špilár
  • 2,617
  • 3
  • 15
  • 28

1 Answers1

1

You can add your custom protocol this way.

Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, user.getName());

ArrayList<ContentValues> data = new ArrayList<ContentValues>();
ContentValues values = new ContentValues();
values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
values.put(ContactsContract.CommonDataKinds.Im.DATA, user.getID());
values.put(ContactsContract.CommonDataKinds.Im.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM);
values.put(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL, "your_protocol");
data.add(values);
intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);

startActivityForResult(intent, 0);
Oliver Kranz
  • 3,741
  • 2
  • 26
  • 31