![]() |
VOOZH | about |
We have seen many apps and websites in which we will get to see a chatbot where we can chat along with the chatbot and can easily get solutions for our questions answered from the chatbot. In this article, we will take a look at building a chatbot in Android.
We will be building a simple application in which we will be building a simple chatbot where we can ask a question to our bot and the bot will answer our questions. Below is the video in which we will get to see what we are going to build in this article. Note that we are going to implement this project using both Java & Kotlin.
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
Navigate to the Gradle Scripts > build.gradle.kts file and add the below dependency to it in the dependencies section.
dependencies {
...
implementation ("com.android.volley:volley:1.2.1")
}
After adding this dependency sync your project.
Navigate to the app > manifests > AndroidManifest.xml and add the below code to it.
<uses-permission android:name="android.permission.INTERNET" />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.
activity_main.xml:
Navigate to the app > java > {package-name}, Right-click on it, New > Java/Kotlin class and name it as Model and add the below code to it. Comments are added inside the code to understand the code in more detail.
Modal File:
Icons used in this file are present in the drawable folder. Navigate to the app > res > layout > Right-click on it > New > layout resource file and name the file as item_user_messages and item_bot_messages and add the below code to it.
For setting data to our items of Chat RecyclerView we have to create an Adapter class. Navigate to the app > java > {package-name}, Right-click on it, New > Java/Kotlin class and name your class as Adapter and add the below code to it. Comments are added inside the code to understand the code in more detail.
Adapter File:
Go to Brainshop.ai generate your simple account with your username and password. Simply create your account on this website. After creating a new account you will get to see the below screen. After creating your account you have to request a new password from the request password option and enter your email address. After adding your email address you have to add the password to your account. Now we are good to go to generate our API key.
Follow the above steps to Generate a new brain for your chatbot. After generating your bot now we will get the API URL for this brain. Navigate to the settings tab inside your created brain you will get to see your bot details as shown below.
Note: Now we will be using this API URL only inside the MainActivity file.
Go to the MainActivity file and refer to the following code. Below is the code for the MainActivity file. Comments are added inside the code to understand the code in more detail.
MainActivity File:
Check out the project on the below link:Github Link