No video

How to Add Contacts Programmatically in Android

  Рет қаралды 13,188

Coding Demos

Coding Demos

Күн бұрын

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: developer.android.com/trainin...
Website: www.codingdemos.com
FaceBook: / codingdemos
Introduction 00:00
Final output 00:15
Android Studio project introduction 03:54
Working with Android Contact Intent 05:10
Conclusion 17:50

Пікірлер: 31
@CodingDemos
@CodingDemos 4 жыл бұрын
Hey guys, I hope you liked this tutorial :) Comment below on topics you want me to cover next.
@99Points
@99Points 4 жыл бұрын
Sir you are doing an awesome job. Keep it up! Full support from me!
@CodingDemos
@CodingDemos 4 жыл бұрын
Hi, thank you for your support :)
@arvindhprasadhsugendran9577
@arvindhprasadhsugendran9577 3 жыл бұрын
to store data to google contacts
@user-hj1sv7qi4r
@user-hj1sv7qi4r 3 жыл бұрын
Thanks!, is it possible to insert fully automatically? without the need for the user to press SAVE? If so, does it requires rooting?
@HmongMovie1
@HmongMovie1 4 жыл бұрын
Hello I like the tutorial very much but one question. How do I code the add without the user confirming the details or without clicking the save?
@CodingDemos
@CodingDemos 4 жыл бұрын
Hi, I'm not sure if we can do that
@99Points
@99Points 4 жыл бұрын
One day you will have millions of subscribers. I know that.
@CodingDemos
@CodingDemos 4 жыл бұрын
Thank you for the motivation, I really appreciate it :)
@miguelaristizabal4996
@miguelaristizabal4996 3 жыл бұрын
I do it but nee to create getPackageManager method and starActivity methoth. How could I do?
@mrjames1014
@mrjames1014 3 жыл бұрын
Are you using kotlin? or what?
@brahimkhodja7624
@brahimkhodja7624 3 жыл бұрын
how add departement name
@telintservicio
@telintservicio 2 жыл бұрын
May be do you know how to insert birthday?
@nome26
@nome26 3 жыл бұрын
hi, thanks for the tutorial. How to save the contact in a real device? i need some permission?
@CodingDemos
@CodingDemos 3 жыл бұрын
This also applies to saving the contact in a physical device
@nome26
@nome26 3 жыл бұрын
@@CodingDemosthanks, but when i try it tells me it can't be saved
@CodingDemos
@CodingDemos 3 жыл бұрын
Do you get any error message in the logcat in Android studio?
@swapnanildas8607
@swapnanildas8607 3 жыл бұрын
Can you upload the code it will be very helpful.
@CodingDemos
@CodingDemos 3 жыл бұрын
Hi, I'm sorry, I don't have the full code. I've put some code snippets in the video description that you may refer to.
@eggwarrior5630
@eggwarrior5630 3 жыл бұрын
Hi love your tutorial but my question is how can i save add contact directly in my app but not in the phone itself
@annarosetrinidadalmario2922
@annarosetrinidadalmario2922 3 жыл бұрын
same question, have you found the answer?
@eggwarrior5630
@eggwarrior5630 3 жыл бұрын
@@annarosetrinidadalmario2922 Nope was hoping someone could help me out with this. I'm building a personal safety application for my FYP
@CodingDemos
@CodingDemos 3 жыл бұрын
Hi, you can get those values from the form and save them inside your database/Firebase. In your app you will then get the contact values which were saved earlier from your database, and show them somewhere in your app.
@eggwarrior5630
@eggwarrior5630 3 жыл бұрын
@@CodingDemos do you have any video references or document that i can learn from? I’m still a rookie at android studio. Thanks im advance
@CodingDemos
@CodingDemos 3 жыл бұрын
@@eggwarrior5630 Are you using Firebase to store user data?
@defifire9980
@defifire9980 2 жыл бұрын
This tutorial is too long... the people who came here its just to see the intend :T
Android Material Design Component - How to Use Sliders in Your App
34:44
How to Insert an Event to Calendar Using Android Intent
18:28
Coding Demos
Рет қаралды 38 М.
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 29 МЛН
Gym belt !! 😂😂  @kauermotta
00:10
Tibo InShape
Рет қаралды 18 МЛН
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН
Android Studio #22: Add Contact by Intent
9:42
CodeDocu Developer C# Asp Net Angular
Рет қаралды 28 М.
How to send Email on Android using Java Intent
10:46
Codes Easy
Рет қаралды 9 М.
Phonebook contacts in RecyclerView
17:37
Kim Pro
Рет қаралды 7 М.
How to quickly copy ALL data off an Android phone | BACKUP
5:18
TroubleChute
Рет қаралды 55 М.
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 29 МЛН