Write your First mesibo Enabled Application - AndroidEstimated reading time: 8 minutes
- Basic Concepts
- Real-Time Messaging
- First App
- Group Messaging
- Reading Messages
- Sync Messages
- Sending Media & Files
- Push Notification
- Voice & Video Calls
- UI Modules
In this part, we will create a simple real-time app for Android.
Please go through the following prerequisites before you read further.
- Read the section First App to learn about creating an app in mesibo console and creating users & access tokens for your app.
- Knowledge of using Android Studio and making basic Android Apps
- Download the source code for the First Mesibo Android App from GitHub.
First Android App
Now let’s quickly start coding:
- Start Android Studio.
- Create a new project with minimum SDK version 16 or higher.
- Android Studio starts Gradle and builds your project. This may take a few seconds. For more information about creating a project in Android Studio, see the Android Studio documentation. https://developer.android.com/training/basics/firstapp/creating-project.html
- Add mesibo SDK to your project by adding gradle dependency and performing gradle sync as explained in installation instructions. Import mesibo API.
- Create two users, each with the User Address
456and App ID
com.mesibo.firstapp. You can refer to the section First App to learn how to create users.
- Modify the token values in the source code to the ones you have generated for each of your demo users.
Example, in Java
DemoUser mUser1 = new DemoUser("xyz", "User-1", "123"); DemoUser mUser2 = new DemoUser("pqr", "User-2", "456");
Example, in Kotlin
internal var mUser1 = DemoUser("xyz", "User-1", "123") internal var mUser2 = DemoUser("pqr", "User-2", "456")
- Initialize mesibo for each user, when they log in.
Before you send and receive real-time messages and calls, you need to initialize Mesibo. The initialization involves the following steps:
- Set your user credentials for authentication: access token using
- Set up Mesibo to invoke your listener class using
- Set up database to store sent and received messages using
- Start Mesibo
You can download the source code for the First Mesibo Android App from GitHub.
Sample mesibo initialization code, using Java in MainActivity.java
Sample mesibo initialization code, in MainActivity.kt
Extend your activity to Implement
mesibo.ConnectionListner class and implement listeners. The easiest way is to click on the
Code menu and click on
Implement Methods and it will automatically generate the code for all the methods.
Sample mesibo Listeners in Java,
Sample mesibo Listeners in Kotlin,
That’s it - you are now ready to receive your first real-time message.
Testing your first application
- Build and Install the Application.
- On the demo app, click on the
Login as User1button.
Mesibo_onConnectionStatusshould cycle through various status information. Finally, you should receive
status=1which indicates that your app is successfully connected to the mesibo real-time server and ready to send and receive real-time messages.
- We will use mesibo console to send a test message. In a later section, we will learn how to send messages from the app itself.
- Go to Console ->Application->Users. You should see the user you have created.
- Go to user details by clicking the
Editbutton. Scroll down, you will see a section to
- Enter 1000 (or anything) in the
Create This Usercheckbox, type message and click on
- You will instantly receive this message in your mobile app and the message will be displayed in a toast.
If you check the logs, you can see that you got the message in
In the previous section, we have used mesibo console to send a message. Now we will quickly learn how to send messages from the app itself. To send messages, we will use
sendMessage real-time API for which we will need destination user, message-id, and the message itself.
Invoke the following function anywhere from your code to send a text message. In a later section, we will learn how to send rich messages.
That’s it, Two users can now send messages to each other using your app! Click on
LAUNCH MESSAGE UI on the app, to try all the messaging features!
Download the First Android App Source Code from GitHub
You can download the source code from GitHub. Once you have set up two users and modified the tokens in the source code, you can install the app on two devices and try it out.
On one device, you can log in as User-1. On another device, you can log in as User-2. These two users can now text each other, send files to each other, make audio and video calls, etc. We will learn more about sending files and making calls in the upcoming sections.
mesibo, android, ios