You are right! Thank you a lot!
2013/8/20 Nobu Games <[email protected]> > I'm not completely sure but I think you need to create separate inserts > for the name and the phone number. So make a separate insert for the phone > number and don't forget to set the correct mime type for that. > > > On Tuesday, August 20, 2013 9:01:48 AM UTC-5, Greenhand wrote: >> >> I have tried to add a contact ContentProvider programmatically but in >> vain. The following is my code: >> >> import android.app.Activity; >> import android.content.ContentUris; >> import android.content.ContentValues; >> import android.net.Uri; >> import android.os.Bundle; >> import android.provider.**ContactsContract.**CommonDataKinds.Phone; >> import android.provider.**ContactsContract.**CommonDataKinds.** >> StructuredName; >> import android.provider.**ContactsContract.Data; >> import android.provider.**ContactsContract.RawContacts; >> import android.view.Menu; >> >> public class MainActivity extends Activity { >> @Override >> protected void onCreate(Bundle savedInstanceState) { >> super.onCreate(**savedInstanceState); >> setContentView(R.layout.**activity_main); >> >> ContentValues values = new ContentValues(); >> Uri rawContactUri = >> getContentResolver().insert(**RawContacts.CONTENT_URI, >> values); >> long rawContactId = ContentUris.parseId(**rawContactUri); >> values.put(Data.RAW_CONTACT_**ID, rawContactId); >> values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_**TYPE); >> values.put(StructuredName.**GIVEN_NAME, "Test"); //the contact name >> values.put(Phone.NUMBER, "123456789"); //the contact phone number >> values.put(Phone.TYPE, Phone.TYPE_MOBILE); >> getContentResolver().insert(**android.provider.** >> ContactsContract.Data.CONTENT_**URI, values); >> } >> >> with permission <uses-permission >> android:name="android.**permission.WRITE_CONTACTS" >> /> >> >> However, the result is pretty weird. The first screenshot shows the name >> "2" instead of "Test" and the second screenshot shows no phone number >> instead of "123456789." Do I miss something? >> > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > --- > You received this message because you are subscribed to a topic in the > Google Groups "Android Developers" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/android-developers/9MJsu5F0NO4/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

