Insert a New Contact Intent

Insert a new contact intent

Finally found a solution, I'm sharing it with you.
That's only a fix for Android version above 4.0.3 and sup. It doesn't work on 4.0 to 4.0.2.

i = new Intent(Intent.ACTION_INSERT);
i.setType(Contacts.CONTENT_TYPE);
if (Integer.valueOf(Build.VERSION.SDK) > 14)
i.putExtra("finishActivityOnSaveCompleted", true); // Fix for 4.0.3 +
startActivityForResult(i, PICK_CONTACT_REQUEST);

Add new contact via intent with multiple phone numbers

Found a solution. It consists in using ContentValues:

    Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
ArrayList<ContentValues> data = new ArrayList<ContentValues>();

// Filling data with phone numbers
for (int i = 0; i < numberOfPhones; i++) {
ContentValues row = new ContentValues();
row.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
row.put(Phone.NUMBER, PhonesNumberList.get(i));
// Setting the type of this phone number to be of Phone.TYPE_WORK
row.put(Phone.TYPE, Phone.TYPE_WORK);
data.add(row);
}

intent.putExtra(ContactsContract.Intents.Insert.NAME, mName);
intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);
startActivity(contactIntent);

How can I add a phone number to an existing contact via Intent?

this is the way to do it:

Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
i.putExtra(Insert.NAME, "TESTTEST");
i.putExtra(Insert.PHONE, "209384");
startActivity(i);

Insert Contact (ContactsContract) via Intent with Image (Photo)

Bitmap bit = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); // your image

ArrayList<ContentValues> data = new ArrayList<ContentValues>();

ContentValues row = new ContentValues();
row.put(Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
row.put(ContactsContract.CommonDataKinds.Photo.PHOTO, bitmapToByteArray(bit));
data.add(row);

Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
intent.putParcelableArrayListExtra(Insert.DATA, data);


Related Topics



Leave a reply



Submit