开发者

Android add contact email

I'm trying to insert a new contact into the Androids contact list. Adding a name and phone numbers works fine, but adding an email address doesn't work. My code:

//name is a string
//phone and email are string arrays
ContentValues values = new ContentValues();
values.put(People.NAME, name);
Uri newPerson = People.createPersonInMyContactsGroup(cr, values);
if (newPerson != null) {
    for (i=0; i<phone.length; i++) {
        Log.i("Phone",""+phone[i]);
        values.clear();
        Uri mobilesUri = Uri.withAppendedPath(newPerson,People.Phones.CONTENT_DIRECTORY);
        values.put(People.Phones.NUMBER,phone[i]);
        values.put(People.Phones.TYPE,People.Phones.TYPE_MOBILE);
        Uri phonesUpdate = cr.insert(mobilesUri, values);
    }
    for (i=0; i<email.length; i++) {
        Log.i("Email",""+email[i]);
        values.clear();
        Uri emailUri = Uri.withAppendedPath(newPerson,People.ContactMethods.CONTENT_DIRECTORY);
        values.put(People.ContactMethods.KIND,People.ContactMethods.KIND_EMAIL);
        values.put(People.ContactMethods.TYPE,People.ContactMethods.TYPE_HOME);
        values.put(People.ContactMethods.DATA,email[i]);
        Uri emailUpdate = cr.insert(emailUri, values);
    }
}

I get an开发者_JAVA百科 error in this line:

values.put(People.ContactMethods.KIND,People.ContactMethods.KIND_EMAIL);

of

error: cannot find symbol

Edit: I forgot to mention I use Xcode/Ant and revision 8 (2.2 (Froyo)).


This works for me:

    values.put(People.ContactMethods.KIND, Contacts.KIND_EMAIL);

which I got from the well-hidden (at least for Contact programming info): developer.android.com: Content Providers: Modifying data in a provider


You may get some help from this example: Android Developers - ContactOperations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜