How to Add Contacts Programmatically in Android
Hi and welcome to another tutorial from CodingDemos :)
In this tutorial, you will learn how to add contacts programmatically in Android.
Here are the steps:
1- Open up Android Studio.
2- Add some checking Inside the addContact button's onClickListener to ensure that the name, email, and phone edittexts are not empty. Otherwise, show an error Toast message.
if (!name.getText().toString().isEmpty() && !email.getText().toString().isEmpty() && !phone
.getText().toString().isEmpty()) {
}else{
Toast.makeText(MainActivity.this, "Please fill all the fields",
Toast.LENGTH_SHORT).show();
}
3- Initialize the Android contact Intent.
Intent intent = new Intent(Intent.ACTION_INSERT);
4- Set the type of intent so that only certain apps that support this action can be used.
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
5- Pass the name, email, and phone values inside the intent using PutExtra.
intent.putExtra(ContactsContract.Intents.Insert.NAME, name.getText().toString());
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, email.getText().toString());
intent.putExtra(ContactsContract.Intents.Insert.PHONE, phone.getText().toString());
6- Before you can call startActivity(), you need to do some checking to ensure that there is an application that can handle this type of action. Otherwise, show an error Toast Message.
if(intent.resolveActivity(getPackageManager()) != null){
startActivity(intent);
}else{
Toast.makeText(MainActivity.this, "There is no app that support this action", Toast.LENGTH_SHORT).show();
}
7- Now build and run the app to see the result :)
Links:
Modify contacts using intents: https://developer.android.com/training/contacts-provider/modify-data#create-an-intent
Website: https://www.codingdemos.com
FaceBook: https://www.facebook.com/Codingdemos
Introduction 00:00
Final output 00:15
Android Studio project introduction 03:54
Working with Android Contact Intent 05:10
Conclusion 17:50
Видео How to Add Contacts Programmatically in Android канала Coding Demos
In this tutorial, you will learn how to add contacts programmatically in Android.
Here are the steps:
1- Open up Android Studio.
2- Add some checking Inside the addContact button's onClickListener to ensure that the name, email, and phone edittexts are not empty. Otherwise, show an error Toast message.
if (!name.getText().toString().isEmpty() && !email.getText().toString().isEmpty() && !phone
.getText().toString().isEmpty()) {
}else{
Toast.makeText(MainActivity.this, "Please fill all the fields",
Toast.LENGTH_SHORT).show();
}
3- Initialize the Android contact Intent.
Intent intent = new Intent(Intent.ACTION_INSERT);
4- Set the type of intent so that only certain apps that support this action can be used.
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
5- Pass the name, email, and phone values inside the intent using PutExtra.
intent.putExtra(ContactsContract.Intents.Insert.NAME, name.getText().toString());
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, email.getText().toString());
intent.putExtra(ContactsContract.Intents.Insert.PHONE, phone.getText().toString());
6- Before you can call startActivity(), you need to do some checking to ensure that there is an application that can handle this type of action. Otherwise, show an error Toast Message.
if(intent.resolveActivity(getPackageManager()) != null){
startActivity(intent);
}else{
Toast.makeText(MainActivity.this, "There is no app that support this action", Toast.LENGTH_SHORT).show();
}
7- Now build and run the app to see the result :)
Links:
Modify contacts using intents: https://developer.android.com/training/contacts-provider/modify-data#create-an-intent
Website: https://www.codingdemos.com
FaceBook: https://www.facebook.com/Codingdemos
Introduction 00:00
Final output 00:15
Android Studio project introduction 03:54
Working with Android Contact Intent 05:10
Conclusion 17:50
Видео How to Add Contacts Programmatically in Android канала Coding Demos
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Android Checkbox TutorialAndroid alertdialog exampleAndroid onActivityResult is Deprecated. What Do I Do Now?Android Firebase Login And User Session Tutorial (Explained)How to Add a Professional Looking Animation in Android With a Few Lines of CodeAndroid Firebase Send a Password Reset Email (Explained)How to Insert an Event to Calendar Using Android IntentHow to prevent a dialog from closing when a button is clickedAndroid Datepicker – Using Datepickerdialog With Button (Explained)Android spinner in custom dialogAndroid custom dialog - Create Android Alertdialog with a custom layoutAndroid Timepicker – Use EditText to Show TimePickerDialog (Explained)Android multiple choice list dialog tutorialAndroid Material Design Colors - Where to Get Color Ideas For Your AppAndroid How to Make a Phone Call With a Button ClickAndroid Firebase User Registration Tutorial (Explained)Android Firebase Send a User a Verification Email (Explained)Android Drop Down List Tutorial Part #2Android floating action button animationsHow to Draw Android TextView Border (Explained)