Android跳转到系统通讯录新增和修改联系人

来源:互联网 发布:网络炮仗什么意思 编辑:程序博客网 时间:2024/05/16 13:42

新增联系人:

Intent intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);intent.putExtra(android.provider.ContactsContract.Intents.Insert.NAME, name);intent.putExtra(android.provider.ContactsContract.Intents.Insert.JOB_TITLE, title);intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE, phone);startActivity(intent);

修改联系人:

Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);intent.setType("vnd.android.cursor.item/person");intent.setType("vnd.android.cursor.item/contact");intent.setType("vnd.android.cursor.item/raw_contact");intent.putExtra(android.provider.ContactsContract.Intents.Insert.NAME, name);intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE, phone);intent.putExtra(android.provider.ContactsContract.Intents.Insert.JOB_TITLE, title);startActivity(intent);


各个字段的api

public static final class Insert {    /** The action code to use when adding a contact */    public static final String ACTION = Intent.ACTION_INSERT;    /**     * If present, forces a bypass of quick insert mode.     */    public static final String FULL_MODE = "full_mode";    /**     * The extra field for the contact name.     * <P>Type: String</P>     */    public static final String NAME = "name";    // TODO add structured name values here.    /**     * The extra field for the contact phonetic name.     * <P>Type: String</P>     */    public static final String PHONETIC_NAME = "phonetic_name";    /**     * The extra field for the contact company.     * <P>Type: String</P>     */    public static final String COMPANY = "company";    /**     * The extra field for the contact job title.     * <P>Type: String</P>     */    public static final String JOB_TITLE = "job_title";    /**     * The extra field for the contact notes.     * <P>Type: String</P>     */    public static final String NOTES = "notes";    /**     * The extra field for the contact phone number.     * <P>Type: String</P>     */    public static final String PHONE = "phone";    /**     * The extra field for the contact phone number type.     * <P>Type: Either an integer value from     * {@link CommonDataKinds.Phone},     *  or a string specifying a custom label.</P>     */    public static final String PHONE_TYPE = "phone_type";    /**     * The extra field for the phone isprimary flag.     * <P>Type: boolean</P>     */    public static final String PHONE_ISPRIMARY = "phone_isprimary";    /**     * The extra field for an optional second contact phone number.     * <P>Type: String</P>     */    public static final String SECONDARY_PHONE = "secondary_phone";    /**     * The extra field for an optional second contact phone number type.     * <P>Type: Either an integer value from     * {@link CommonDataKinds.Phone},     *  or a string specifying a custom label.</P>     */    public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";    /**     * The extra field for an optional third contact phone number.     * <P>Type: String</P>     */    public static final String TERTIARY_PHONE = "tertiary_phone";    /**     * The extra field for an optional third contact phone number type.     * <P>Type: Either an integer value from     * {@link CommonDataKinds.Phone},     *  or a string specifying a custom label.</P>     */    public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";    /**     * The extra field for the contact email address.     * <P>Type: String</P>     */    public static final String EMAIL = "email";    /**     * The extra field for the contact email type.     * <P>Type: Either an integer value from     * {@link CommonDataKinds.Email}     *  or a string specifying a custom label.</P>     */    public static final String EMAIL_TYPE = "email_type";    /**     * The extra field for the email isprimary flag.     * <P>Type: boolean</P>     */    public static final String EMAIL_ISPRIMARY = "email_isprimary";    /**     * The extra field for an optional second contact email address.     * <P>Type: String</P>     */    public static final String SECONDARY_EMAIL = "secondary_email";    /**     * The extra field for an optional second contact email type.     * <P>Type: Either an integer value from     * {@link CommonDataKinds.Email}     *  or a string specifying a custom label.</P>     */    public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";    /**     * The extra field for an optional third contact email address.     * <P>Type: String</P>     */    public static final String TERTIARY_EMAIL = "tertiary_email";    /**     * The extra field for an optional third contact email type.     * <P>Type: Either an integer value from     * {@link CommonDataKinds.Email}     *  or a string specifying a custom label.</P>     */    public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";    /**     * The extra field for the contact postal address.     * <P>Type: String</P>     */    public static final String POSTAL = "postal";    /**     * The extra field for the contact postal address type.     * <P>Type: Either an integer value from     * {@link CommonDataKinds.StructuredPostal}     *  or a string specifying a custom label.</P>     */    public static final String POSTAL_TYPE = "postal_type";    /**     * The extra field for the postal isprimary flag.     * <P>Type: boolean</P>     */    public static final String POSTAL_ISPRIMARY = "postal_isprimary";    /**     * The extra field for an IM handle.     * <P>Type: String</P>     */    public static final String IM_HANDLE = "im_handle";    /**     * The extra field for the IM protocol     */    public static final String IM_PROTOCOL = "im_protocol";    /**     * The extra field for the IM isprimary flag.     * <P>Type: boolean</P>     */    public static final String IM_ISPRIMARY = "im_isprimary";    /**     * The extra field that allows the client to supply multiple rows of     * arbitrary data for a single contact created using the {@link Intent#ACTION_INSERT}     * or edited using {@link Intent#ACTION_EDIT}. It is an ArrayList of     * {@link ContentValues}, one per data row. Supplying this extra is     * similar to inserting multiple rows into the {@link Data} table,     * except the user gets a chance to see and edit them before saving.     * Each ContentValues object must have a value for {@link Data#MIMETYPE}.     * If supplied values are not visible in the editor UI, they will be     * dropped.  Duplicate data will dropped.  Some fields     * like {@link CommonDataKinds.Email#TYPE Email.TYPE} may be automatically     * adjusted to comply with the constraints of the specific account type.     * For example, an Exchange contact can only have one phone numbers of type Home,     * so the contact editor may choose a different type for this phone number to     * avoid dropping the valueable part of the row, which is the phone number.     * <p>     * Example:     * <pre>     *  ArrayList&lt;ContentValues&gt; data = new ArrayList&lt;ContentValues&gt;();     *     *  ContentValues row1 = new ContentValues();     *  row1.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);     *  row1.put(Organization.COMPANY, "Android");     *  data.add(row1);     *     *  ContentValues row2 = new ContentValues();     *  row2.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);     *  row2.put(Email.TYPE, Email.TYPE_CUSTOM);     *  row2.put(Email.LABEL, "Green Bot");     *  row2.put(Email.ADDRESS, "android@android.com");     *  data.add(row2);     *     *  Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);     *  intent.putParcelableArrayListExtra(Insert.DATA, data);     *     *  startActivity(intent);     * </pre>     */    public static final String DATA = "data";    /**     * Used to specify the account in which to create the new contact.     * <p>     * If this value is not provided, the user is presented with a disambiguation     * dialog to chose an account     * <p>     * Type: {@link Account}     */    public static final String EXTRA_ACCOUNT = "android.provider.extra.ACCOUNT";    /**     * Used to specify the data set within the account in which to create the     * new contact.     * <p>     * This value is optional - if it is not specified, the contact will be     * created in the base account, with no data set.     * <p>     * Type: String     */    public static final String EXTRA_DATA_SET = "android.provider.extra.DATA_SET";}

阅读全文
0 0
原创粉丝点击