Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Contact using Intent in Android

Tags:

android

I'm making an application in which user can add users from the application into his contacts.

Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, bean.getMobileNo());
intent.putExtra(ContactsContract.Intents.Insert.NAME, bean.getName());
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, bean.getEmailID());
startActivity(intent);

so adding it is not the issue the issue when it goes to add contact screen and if the user presses back button the contact is getting saved even if the user doesn't want to save the contact.

I want to do this using Intent only not through app. Is there any solution for this or is it device specific?

like image 339
Harshad Pawar Avatar asked Feb 27 '26 03:02

Harshad Pawar


1 Answers

Try this

/** * Open the add-contact screen with pre-filled info */

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);

intent.putExtra(ContactsContract.Intents.Insert.NAME, bean.getName());
intent.putExtra(ContactsContract.Intents.Insert.PHONE, bean.getMobileNo());
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, bean.getEmailID());

context.startActivity(intent);
like image 58
Shailesh Avatar answered Feb 28 '26 20:02

Shailesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!