Apparently, the following code stopped working in the new SDK. Can
anybody give an update?
To be more specific, the last line of the code
ContentURI emailUpdate =
getContentResolver().insert(newPerson.addPath(Contacts.ContactMethods.CONTE
NT_URI.getPath()),
email);
Because addPath() is no longer available, can any expert give an
update?
Thanks a ton
Here's some code to demonstrate this:// create the values for your test person
ContentValues person = new ContentValues();
person.put(Contacts.People.NAME, "Test Name");
person.put(Contacts.People.COMPANY, "Test Company");
person.put(Contacts.People.NOTES, "Test Notes");
// insert the information in the contacts
ContentURI newPerson =
getContentResolver().insert(Contacts.People.CONTENT_URI, person);
// check to make sure the update was successful. If so, your
ContentURI returned
// will look something like this
// content://contacts/people/1
//
if (newPerson != null) {
// create values to add a phone number
ContentValues number = new ContentValues();
number.put(Contacts.Phones.PERSON_ID,
newPerson.getPathLeaf());
number.put(Contacts.Phones.NUMBER, "(888) 555-1212");
// insert it into the contacts
ContentURI phoneUpdate =
getContentResolver().insert(Contacts.Phones.CONTENT_URI, number);
// create values for the email address
ContentValues email = new ContentValues();
email.put(Contacts.ContactMethods.PERSON_ID,
newPerson.getPathLeaf());
email.put(Contacts.ContactMethods.KIND,
Contacts.ContactMethods.EMAIL_KIND);
email.put(Contacts.ContactMethods.TYPE,
Contacts.ContactMethods.EMAIL_KIND_HOME_TYPE);
email.put(Contacts.ContactMethods.DATA, "t...@test.com");
// the key here is that when you insert the email into the
Contacts,
be sure to use the path for the person
// that was returned originally, and then add the path to the
ContactMethods at the end of this URL
ContentURI emailUpdate =
getContentResolver().insert(newPerson.addPath(Contacts.ContactMethods.CONTE
NT_URI.getPath()),
email);
> Apparently, the following code stopped working in the new SDK. Can
> anybody give an update?
> To be more specific, the last line of the code
> ContentURI emailUpdate =
> getContentResolver().insert(newPerson.addPath(Contacts.ContactMethods.CONTE
> NT_URI.getPath()),
> email);
> Because addPath() is no longer available, can any expert give an
> update?
> Thanks a ton
> Here's some code to demonstrate this:// create the values for your test person
> ContentValues person = new ContentValues();
> person.put(Contacts.People.NAME, "Test Name");
> person.put(Contacts.People.COMPANY, "Test Company");
> person.put(Contacts.People.NOTES, "Test Notes");
> // insert the information in the contacts
> ContentURI newPerson =
> getContentResolver().insert(Contacts.People.CONTENT_URI, person);
> // check to make sure the update was successful. If so, your
> ContentURI returned
> // will look something like this
> // content://contacts/people/1
> //
> if (newPerson != null) {
> // create values to add a phone number
> ContentValues number = new ContentValues();
> number.put(Contacts.Phones.PERSON_ID,
> newPerson.getPathLeaf());
> number.put(Contacts.Phones.NUMBER, "(888) 555-1212");
> // insert it into the contacts
> ContentURI phoneUpdate =
> getContentResolver().insert(Contacts.Phones.CONTENT_URI, number);
> // create values for the email address
> ContentValues email = new ContentValues();
> email.put(Contacts.ContactMethods.PERSON_ID,
> newPerson.getPathLeaf());
> email.put(Contacts.ContactMethods.KIND,
> Contacts.ContactMethods.EMAIL_KIND);
> email.put(Contacts.ContactMethods.TYPE,
> Contacts.ContactMethods.EMAIL_KIND_HOME_TYPE);
> email.put(Contacts.ContactMethods.DATA, "t...@test.com");
> // the key here is that when you insert the email into the
> Contacts,
> be sure to use the path for the person
> // that was returned originally, and then add the path to the
> ContactMethods at the end of this URL
> ContentURI emailUpdate =
> getContentResolver().insert(newPerson.addPath(Contacts.ContactMethods.CONTE
> NT_URI.getPath()),
> email);
ContentValues person = new ContentValues();
person.put(Contacts.People.NAME, "Test User");
person.put(Contacts.People.COMPANY, "Test Company");
person.put(Contacts.People.NOTES, "eNotes");
Uri newPerson =
context.getContentResolver().insert(Contacts.People.CONTENT_URI,
person);
if (newPerson != null) {
// add a mobile phone number
ContentValues number = new ContentValues();
List<String> pathList = newPerson.getPathSegments();
String pathLeaf = pathList.get(pathList.size() -1 );
number.put(Contacts.Phones.PERSON_ID,pathLeaf);
number.put(Contacts.Phones.NUMBER, "(408) 111-1111");
// insert it into the contacts
Uri phoneUpdate =
context.getContentResolver().insert(Contacts.Phones.CONTENT_URI,
number);
}
But the email part doesn't seem to work though.
On Feb 22, 7:52 am, CJ <Chunyu.Ji...@gmail.com> wrote:
> Apparently, the following code stopped working in the new SDK. Can
> anybody give an update?
> To be more specific, the last line of the code
> ContentURI emailUpdate =getContentResolver().insert(newPerson.addPath(Contacts.ContactMethods.CONT E
> NT_URI.getPath()),
> email);
> Because addPath() is no longer available, can any expert give an
> update?
> Thanks a ton
> Here's some code to demonstrate this:// create the values for your test person
> ContentValues person = new ContentValues();
> person.put(Contacts.People.NAME, "Test Name");
> person.put(Contacts.People.COMPANY, "Test Company");
> person.put(Contacts.People.NOTES, "Test Notes");
> //insertthe information in the contacts
> ContentURI newPerson =getContentResolver().insert(Contacts.People.CONTENT_URI, person);
> // check to make sure the update was successful. If so, your
> ContentURI returned
> // will look something like this
> // content://contacts/people/1
> //
> if (newPerson != null) {
> // create values to add a phone number
> ContentValues number = new ContentValues();
> number.put(Contacts.Phones.PERSON_ID,
> newPerson.getPathLeaf());
> number.put(Contacts.Phones.NUMBER, "(888) 555-1212");
> //insertit into the contacts
> ContentURI phoneUpdate =getContentResolver().insert(Contacts.Phones.CONTENT_URI, number);
> // create values for the email address
> ContentValues email = new ContentValues();
> email.put(Contacts.ContactMethods.PERSON_ID,
> newPerson.getPathLeaf());
> email.put(Contacts.ContactMethods.KIND,
> Contacts.ContactMethods.EMAIL_KIND);
> email.put(Contacts.ContactMethods.TYPE,
> Contacts.ContactMethods.EMAIL_KIND_HOME_TYPE);
> email.put(Contacts.ContactMethods.DATA, "t...@test.com");
> // the key here is that when youinsertthe email into the
> Contacts,
> be sure to use the path for the person
> // that was returned originally, and then add the path to the
> ContactMethods at the end of this URL
> ContentURI emailUpdate =getContentResolver().insert(newPerson.addPath(Contacts.ContactMethods.CONT E
> NT_URI.getPath()),
> email);