AsadYarKhan
AsadYarKhan

Reputation: 688

Open A Contact Activity of Android with some fields which are already inserted

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, "[email protected]");
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.

Upvotes: 1

Views: 720

Answers (2)

San
San

Reputation: 5697

You might have imported Contacts.Intents.Insert. There is no Data in this class.

You have to import ContactsContract.Intents.Insert.

For website try this code,

  ArrayList<ContentValues> data = new ArrayList<ContentValues>();
  ContentValues row1 = new ContentValues();
  row1.put(Data.MIMETYPE, Website.CONTENT_ITEM_TYPE);
  row1.put(Website.URL, "www.urwebsite.com");
  row1.put(Website.LABEL, "abc");
  row1.put(Website.TYPE, Website.TYPE_HOME);
  data.add(row1);
  Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
  intent.putParcelableArrayListExtra(Insert.DATA, data);
  startActivity(intent);

Upvotes: 1

Joe Malin
Joe Malin

Reputation: 8641

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.

Upvotes: 2

Related Questions