Setup
We’ll get started by setting up the SDK first.
Android
The Mitter.io Android SDK is distributed freely via jCenter and you can add it easily to your project by adding it as a standard dependency.
Creating a new project
Create a new Android app project by following the standard procedure listed below. Alternatively, you can skip the setup part by cloning our starter template and loading it into Android Studio.
To create a project from scratch, do the following:
Go to File
Click on New, followed by New Project
Follow the steps, keep everything set to default or customize to your needs
Adding dependency
Now add the Android SDK to your newly created project by opening up your build.gradle
file and pasting the following line in the dependencies block:
Once that is added, perform a Gradle sync.
Basic setup
Now that you’ve added the SDK, the next step is to add some initial configuration for the SDK to work.
Note: This documentation contains code snippets for both Kotlin and Java. Switch to the relevant tab while building the demo.
To start working, you need to configure a Mitter
object with your application details, which you can access from the Mitter.io Dashboard.
Before you proceed, visit the Mitter.io Dashboard, create an application and grab the application ID.
Next, you need to create a custom implementation of the Application
class for your app. You can do so by creating a new class and extending the Application
class:
Once that’s in place, override the onCreate()
method. This is where you’ll be configuring the Mitter
object.
Your custom Application
class should look something like this:
Just defining the Mitter
object isn’t enough. You need to configure it with the application ID that you retrieved from the Mitter.io Dashboard.
Here's how to do that: Just paste this inside your onCreate()
method in the MyApp
class:
Using the SDK with containerised Mitter.io
If you're using the Mitter.io docker container, then you need to override the default API endpoint in the SDK, as follows:
That’s all you need to do for the very basic configuration. It’s not ready to connect with the platform just yet, but we’ll get to that part in the later sections.
Setup FCM
Mitter.io works hand-in-hand with Firebase Cloud Messaging (FCM) to deliver messages in real-time to Android devices.
To start receiving messages, you need to setup FCM in your Android app and make a couple of changes in your application in the Mitter.io Dashboard.
First of all, you need to setup FCM in your Android project. The steps for this setup are beyond the scope of this tutorial, and since Google has done a pretty good job explaining the same, you can check out their docs if you haven’t already added FCM to your project.
After you’re through with that, the only thing that's left is to feed your FCM server key in your Mitter.io application inside the Dashboard.
You can do that by following these steps:
Open the Mitter.io Dashboard and select your application from the list
Go to the Properties tab
Click on New Property -> Google -> FCM -> FCM Property
You’ll get a modal where you need to fill out your app’s instance ID, which can be easily retrieved from the Google Cloud Console
Also, you need to feed in your FCM server key, which can be accessed from your FCM admin panel
After you’re done feeding this data, click on New FCM Configuration Property
Once you’ve completed these steps, you need to register a delivery endpoint for Mitter.io to deliver your messages.
In your Android project, create a class called MyFirebaseMessagingService
which extends FirebaseMessagingService
and override the onNewToken()
method.
In the onNewToken()
you need to get a reference to your Mitter
object which you declared in your custom Application
class.
Now that you have a reference to the Mitter
object, you need to register the token with Mitter.io. Just add the following piece of code in your onNewToken()
method:
Once that is done, the next step is to intercept any incoming push messages and pass them to the SDK for processing.
Get started by overriding the onMessageReceived()
method and adding this piece of code inside the method:
Okay, the SDK is all set to intercept incoming messages and process them. The only thing that’s left is to register a callback on the Mitter
object to get notified when a new message arrives.
Head back to your custom Application
class and register a OnPushMessageReceivedCallback
on the Mitter
object that you had already created.
You’re now done with the basic setup. Let’s move on to set up a user to start interacting with the platform and send messages.
Last updated