1. Hands MDM SDK
  2. Android Quickstart
  3. MDM Modules
  4. MDM Notification

MDM Notification

Module responsible for delivering and exhibiting regular, image or images carousel notifications with segmentation in the application.


Before starting

To integrate MDM notifications module, the application needs to have push notifications with Firebase integrated.

If you do not have push notifications with Firebase integrated to your application, follow the instructions at https://firebase.google.com/docs/


If you want to differentiate a notification originated from MDM or a notification that you have:

if (MDMNotification.isMDMNotification(remoteMessage.getData())) {
    MDMNotification.processNotification(remoteMessage.getData(), getApplicationContext());
} else {
    // My Notification
}

 

Add the following service to your manifesto, inside the application tag:

<service
    android:name="br.com.hands.mdm.libs.android.notification.services.MDMMessagingService"
    android:exported="false"
    android:stopWithTask="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

 


Do you have your own classes extending the Firebase classes and do not want to implement the services above?

Follow the instructions below:

1. To register the token provided by Firebase, add the following code to the onNewToken method overload in the class extending FirebaseMessagingService:

MDMNotification.registerToken(newToken, getApplicationContext());

 

2. To receive MDM push, add the following code to the onMessageReceived method overload in the class extending FirebaseMessagingService:

if (MDMNotification.isMDMNotification(remoteMessage.getData())) {
    MDMNotification.processNotification(remoteMessage.getData(), getApplicationContext());
}

 


Specific implementation:

  • Push Notification

For the implementation of the push notification format, nothing else is needed.

 

  • Inbox

For the implementation of the Inbox format, add the following code for when you want to display the content:

startActivity(new Intent(getApplicationContext(), MDMInboxActivity.class));

 

To customize the title bar text, add the following code to your application:

MDMInbox.setTitle("Inbox");

 

To customize the color of the title bar, add the following code to your application:

MDMInbox.setStatusBarColor("#96221B");
MDMInbox.setToolBarColor("#B3342F");

 

To customize the active tabs in a fixed way, add the following code to your application, change it as needed:

MDMInbox.setActiveTabs(new MDMInbox.Tab[]{
    MDMInbox.Tab.COUPONS,
    MDMInbox.Tab.NOTIFICATIONS,
    MDMInbox.Tab.APPINSTALL,
    MDMInbox.Tab.MARKETPLACE
});

 

To customize the active tabs in a variable way, add the following code when you call the content screen, change it as needed:

Intent intent = new Intent(getApplicationContext(), MDMInboxActivity.class);

MDMInboxConfig inboxConfig = new MDMInboxConfig();

inboxConfig.setActiveTabs(new MDMInbox.Tab[]{
        MDMInbox.Tab.NOTIFICATIONS,
        MDMInbox.Tab.COUPONS,
        MDMInbox.Tab.APPINSTALL,
        MDMInbox.Tab.MARKETPLACE
});

inboxConfig.setSelectedTab(MDMInbox.Tab.COUPONS);

intent.putExtra(MDMNotification.INBOX_CONFIG_KEY, inboxConfig);

startActivity(intent);

 

  • InApp Message

For the implementation of the InApp format, add the following code to your application.

MDMInApp.start(getApplicationContext());

 


Integration with Firebase

To send push notifications through the Firebase service, we need a file called Service Account Key. To obtain this file, you must follow the steps below:

NOTE: When accessing the links below, make sure that the project selected at the top of the page is the same project as your app in Firebase.

 

1. Create a specific Role to send Push Notification

Go to the following address: https://console.developers.google.com/iam-admin/roles

Start creating a Role and name it “Hands MDM”.

Add the following permissions:

cloudmessaging.messages.create
Permission to send notifications and data messages via FCM HTTP API and AdminSDK

resourcemanager.projects.get
resourcemanager.projects.getIamPolicy
Permission to retrieve project information from Firebase

Save to finish the process.

 

2. Create a Service Account with the Role previously created

Go to the following address https://console.cloud.google.com/iam-admin/serviceaccounts

Start creating a Service Account and name it “Hands MDM”.

Proceed to the next step and assign the Role created earlier.

Skip the last step and save to finish the process.

 

3. Include a Key in the Service Account and obtain the file

After saving, you will see a listing of all Service Accounts. Select the Service Account created with the name “Hands MDM” to edit.

Add new key in JSON format.

When adding the key, a file will be downloaded automatically.

 


Opt-out

To opt-out module, just call the following command:

MDMNotification.setOptOut(getApplicationContext(), true);

To undo the module opt-out, just call the following command:

MDMNotification.setOptOut(getApplicationContext(), false);