Once we have inserted a record in our database, we can add more information to it. In our example, we have only the name of the contact, now let's add a mobile number to it.
I created an URI object (mUri) in the last line, to use it here.
Let's create another URI, this time a URI to access the phones resource:
Uri mMobileUri = Uri.withAppendedPath(mUri, People.Phones.CONTENT_DIRECTORY);
We append to the new URI the contact URI using ".withAppendedPath"
We can create other ContentValue objects or use the same ones we were using before. We are going to use the same as before (this way we optimize code), but before using it, we have to clear the “mValues" contents with:
In Android Contacts we can enter different kinds of telephone numbers, we have to set what kind of phone we are going to insert. Our intention is to set a “Mobile phone number", so we set this with:
Now we put the mobile number.
And now we do the “insert" in the row with:
getContentResolver().insert( mMobileUri, mValues);