![]() |
Contacts app in android device is a system app that comes installed on your android device. Different devices have different UI for the contacts app. In this article, we will take a look at how we can build our own contacts app in Android Studio. What we are going to build in this article?We will be building a simple application in which we will be displaying the list of contacts that are stored in the user’s device. Along with that we will be also adding a feature to save a new contact, filter contacts from the list using the search bar, and many more. Below is the video in which we will get to see what we are going to build in this article. Step by Step ImplementationStep 1: Create a New Project To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language. Step 2: Add dependency and JitPack Repository As we will have to request the user’s permissions to display contacts from the device in the app, that we have to ask for the user’s permissions. So for getting user’s permissions we will be using Dexter for getting user’s permissions in runtime. For using Dexter and we will be also using text drawable dependency for displaying text inside drawable now we have added the below dependency in build.gradle file. Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.
Add the JitPack repository to your build file. Add it to your root build.gradle at the end of repositories inside the allprojects{ } section.
Now sync your project and we will move further for working with the AndroidManifest.xml file. Step 3: Adding permissions in the AndroidManifest.xml Navigate to the app > AndroidManifest.xml file and add the below permissions to it. Comments are added in the code to get to know in more detail. XML
After adding permissions now we will be moving towards creating a new activity for different screens in our app. Step 4: Creating new empty activities Creating a new activity for saving new contact: Refer to the How to Create New Activity in Android Studio and name your activity as CreateNewContactActivity. This activity will be used for creating a new contact for our app. Creating a new activity for displaying contact details: Similarly, create another empty activity and name your activity as ContactDetailActivity. This activity will be used to make a call to that contact or for sending an SMS. Step 5: Working with the activity_main.xml file Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. XML
Step 6: Creating a modal class for storing contacts Navigate to the app > java > app’s package name > Right-click on it > New > Java class and name it as ContactsModal and add below code to it. Comments are added in the code to get to know in more detail. Java
Step 7: Creating a layout file for the item to be displayed in RecyclerView Navigate to the app > res > layout > Right-click on it > New > Layout Resource file and name it as contacts_rv_item and add the below code to it. Comments are added in the code to get to know in more detail. XML
Step 8: Creating an adapter class for setting data to each item Navigate to the app > java > your app’s package name > Right-click on it > New > Java class and name it as ContactsRVAdapter and add the below code to it. Comments are added in the code to get to know in more detail. Java
Step 9: Creating a new menu resource file for adding search view in the toolbar Navigate to the app > res > Right-click on it > New > Android Resource directory and name it as menu after that right-click on the menu and click on New > Menu resource directory. After that name that files as search_menu and add the below code to it. Comments are added in the code to get to know in more detail. or you may refer to this article How to Create Menu Folder & Menu File in Android Studio? XML
Step 10: Working with the MainActivity.java file Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail. Java
Step 11: Working with the CreateNewContactActivity Below is the code for both activity_create_new_contact.xml and CreateNewContactActivity.java file. Comments are added inside the code to understand the code in more detail. XML
Java
Step 12: Working with the ContactDetailActivity Below is the code for both activity_contact_detail.xml and ContactDetailActivity.java file. Comments are added inside the code to understand the code in more detail. XML
Java
Now run your app and see the output of the app.
Output: Check out the project on below Github link: https://github.com/ChaitanyaMunje/GFG-Back4App/tree/ContactsApp |
Reffered: https://www.geeksforgeeks.org
Android |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |