Migrate your Android Push Notifications Service from Azure to Bluemix

Share this post:

Using Azure Android Push Documentation as a starting point, this blog will guide you through the steps to migrate your existing Azure push notification enabled Android application to use Push Notifications on Bluemix.

Follow these Steps to Migrate Your Android App

Create a New Push Notifications Service Instance on Bluemix

To start, create an account on Bluemix and provision a new Push Notifications Service instance. Once created, navigate to the Manage tab and click the Configure Now button.


Underneath GCM/FCM Push Credentials on the right, input your FCM/GCM Project ID and API Key (same key used in Azure) and click Save.

Once you have successfully configured your Push Notifications instance, navigate to the Service Credentials tab, click View Credentials and take note of your appGuid and clientSecret values. You will need to add them to your Android Studio project later.


Update FCM Project Settings

Now, let’s make some changes to your Firebase Cloud Messaging project.

Note: If you are using a legacy Google Cloud Messaging project (created around or prior to Sept 20th, 2016), skip down to Update build.gradle to Include Bluemix Push Notifications Dependencies.

Once you navigate to your FCM project, open the Project Settings dashboard and select ADD APP.  You should have your existing package name here already, but we need to add the Bluemix Push Notifications package here to handle proper interactions between the SDK, FCM, and Bluemix.


Select Add Firebase to your Android app and enter the package name then click ADD APP.


The google-services.json that you are prompted to download needs to replace the existing .json in your Android Studio project at YourAndroidProject\app\google-services.json. You can simply copy and paste the entire contents of the new google-services.json over the existing if Android Studio gives you problems when attempting to copy in the file directly.

Update build.gradle to Include Bluemix Push Notifications Dependencies

Now that you have updated your google-services.json, let’s update your build.gradle file at YourAndroidProject\app\build.gradle.

First, replace the existing repository:

 repositories {
maven {
url ""


repositories {

Then, replace the Azure and google play services dependencies:

compile ''
compile ''
compile ''

With the Bluemix Push Notifications SDK dependency:

compile ('')

Update AndroidManifest.xml

First, let’s update the permissions to include the following for Bluemix Push Notifications:

<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

The necessary INTERNET and GET_ACCOUNTS permissions should already exist. The is not needed and can be removed.

Next, remove the meta data tag for google play services; it’s not needed.

<meta-data android:name="" android:value="@integer/google_play_services_version" />

Now, the intent filter added for Azure needs to be changed from:

<service android:name=".MyInstanceIDService">
<action android:name=""/>


<action android:name="Your_Android_Package_Name.IBMPushNotification"/>
<category android:name="android.intent.category.DEFAULT"/>

Note that the instanceIDservice is not needed, you can remove the entire service wrapper. Also, be sure to update Your_Android_Package_Name with your specific Android application’s package. Be aware that whichever activity you include this intent-filter within is the activity that will start when your users tap the notification.

Next, find the registration service tag within the application tag:

<service android:name=".RegistrationIntentService" android:exported="false">

Replace that block with the following:

<service android:name=""
android:exported="true" >
<action android:name"" />
android:exported="true" >
<action android:name="" />

Lastly, find the code for the Azure broadcast receiver:[/code]

 <receiver android:name="" android:permission="">
<action android:name="" />
<category android:name="<your package name>" />

And completely replace with the Bluemix Push Notifications notification handler:

<activity android:name="" android:theme="@android:style/Theme.NoDisplay" />

Updating Java Code

Now, on to the easy part! Unlike Azure, with Bluemix Push Notifications you do not need to write additional classes to integrate push into your mobile app. Therefore, you can remove the NotificationSettings, the MyInstanceIDService, the RegistrationIntentService, and  MyHandler classes entirely.

You can also remove the following imports from your MainActivity :


And replace them with:


Once removed, you will need to remove the remaining erroneous code within your MainActivity. Remove the following static variables:

 public static Boolean isVisible = false;
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;

And replace with:

private MFPPush push;
private MFPPushNotificationListener notificationListener;

Now, look for the following methods that you added for Azure and remove them completely; checkPlayServices(), registerWithNotificationHubs(), and ToastNotify().

Once removed, find the code within your onCreate():

    NotificationsManager.handleNotifications(this, NotificationSettings.SenderId, MyHandler.class);

And replace with Bluemix Core and Push Notifications initialization:

    // Initialize the SDK for Android
BMSClient.getInstance().initialize(this, BMSClient.REGION_US_SOUTH);

//Initialize client Push SDK for Java
push = MFPPush.getInstance();
push.initialize(getApplicationContext(), "appGUID", "clientSecret");

Be sure to input the correct REGION, appGUID, and clientSecret values gathered from the Bluemix Push Notifications dashboard earlier.

Underneath push initialization, insert the following code to register the device with your Bluemix Push Notifications instance when the app starts:

//Register Android devices
push.registerDevice(new MFPPushResponseListener<String>() {
public void onSuccess(String response) {
//handle success here
//This is where you would call the subscribe to tag api
public void onFailure(MFPPushException ex) {
//handle failure here

You will also need to create a NotificationHandler, so add this code as well to your onCreate:

//Handles the notification when it arrives
notificationListener = new MFPPushNotificationListener() {
public void onReceive (final MFPSimplePushNotification message){
// Handle Push Notification
// This is where you would display a toast, alert, or
// create a new intent to a desired activity etc...

Lastly, we need to update the <em>onResume() </em>and <em>onPause() </em> functions to manage the SDK listener. First, remove all references to <em>isVisible = true </em>and <em>isVisible=false</em>. You will not need to override the <em>onStart()</em> and <em>onStop() </em>function callls anymore, but you will need the following:

protected void (){
if(push != null) {
protected void onPause() {
if (push != null) {

This code let’s the SDK know when to handle an inbound push notification and when to hold it for the next time the app is brought to the foreground.

Sending a Push Notification

To send a push notification to your registered Android device you can use the push dashboard’s Send Notifications option or use the Push Notifications REST api to make REST requests to your instance.

For more information on Bluemix Push Notifications, be sure to check out tagging and other advanced documentation.

More How-tos stories
April 5, 2019

IBM Cloud App ID: Updated Runtime APIs Provide Tighter Interoperability for Your Cloud-Native Apps

As part of our efforts to tighten interoperability and broaden the frameworks that are able to use IBM Cloud App ID, we've updated the runtime APIs.

Continue reading

February 11, 2019

IBM Cloud Mobile Foundation: Top-10 Features to Boost Your App Rating

The Mobile Foundation service offers many hidden gems that developers often gloss over. In this post, we highlight the top 10 features that increase user engagement as well as improve app ratings. 

Continue reading

February 8, 2019

Distribute CoreML Models Securely Using Mobile Foundation Service

IBM Mobile Foundation is excited to introduce a feature to manage the distribution of CoreML models.

Continue reading