VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-create-a-chatbot-in-android-with-brainshop-api/

⇱ How to Create a Chatbot in Android with BrainShop API? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Create a Chatbot in Android with BrainShop API?

Last Updated : 23 Jul, 2025

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

What we are going to build in this article? 

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.  

Steps to Implement Chatbot in Android

Step 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.

Step 2: Add the dependency for API call

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.


Step 3: Adding permissions to the internet in the AndroidManifest.xml file

Navigate to the app > manifests > AndroidManifest.xml and add the below code to it. 

<uses-permission android:name="android.permission.INTERNET" />


Step 4: 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. 

activity_main.xml:


Step 5: Creating a Model class for storing our messages

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:


Step 6: Creating a layout file for user & bot messages

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. 


Step 7: Working with the Adapter class

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:


Step 8: Generating API key for using the chatbot service

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. 

👁 Image


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.

👁 Image

Note: Now we will be using this API URL only inside the MainActivity file. 


Step 9: Working with 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

Output: 

Comment

Explore