ArrayList<ContentValues> data = new ArrayList<ContentValues>();
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);
I did not find it in
android.provider.ContactsContract.Intents.Insert.Data (which is using in second last instruction)
there is no Data Variable in Insert Class , I am using API-8 v2.2
Please help is their any other way to do this ?
I want to fill the data in add contact like this.
If you look at the javadoc for ContactsContract.Intents.Insert, you’ll see a bunch of constants like COMPANY, JOBTITLE, etc. You should use those to populate the extras of your Intent. Only use the DATA key if you don’t see a constant. The documentation is not clear on this, but in fact the People app only accepts some column values in DATA.
For example, instead of doing
row.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
row.put(Organization.COMPANY, “Android”);
do
intent.putExtra(Intents.Insert.COMPANY, “Android”);
That should work.
I’m not sure what you mean by “there is no Data Variable in Insert Class”. There shouldn’t be. Insert.DATA is a constant that names a key for putExtra.