Skip to content

Android Push Notification

Introduction

Create a project as follows : Firebase Console

Add Project

Select Android icon :

Select OS

Once you've entered your package name, put the google-service.json file in the root directory as shown in the image download step :

Download Config

Add the following codes to your project-level build.gradle file and app-level file as shown in the picture :

Gradle Config

If you complete these steps you will see a step to verify the following. (You can skip this step) :

Verify Step

Go back to the main page and click on the project settings :

Project Settings

Select cloud messaging and get server key :

Server Key

After entering https://panelv2.segmentify.com, enter the settings as below :

Sgf Settings

After selecting Push, click the Android tab and enter your server key :

Sgf Push Settings

Permission Info

Used to send deviceToken of users who give push permission.

NotificationModel model = new NotificationModel();
model.setDeviceToken(FirebaseInstanceId.getInstance().getToken());
model.setType(NotificationType.PERMISSION_INFO);
SegmentifyManager.INSTANCE.sendNotification(model);

TIPS The first installers of the application can be sent at this time because they already allow


View

Sent when the user sees push.

NotificationModel model = new NotificationModel();
model.setType(NotificationType.VIEW);
model.setInstanceId(data.get("instanceId"));
model.setProductId(data.get("productId"));
SegmentifyManager.INSTANCE.sendNotificationInteraction(model);

instanceId and productId will be in the notification data


Click

It will be sent when the user clicks notification.

We need to send data to the page after clicking :

Intent intent = new Intent(this, EventActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("instanceId",data.get("instanceId"));
intent.putExtra("productId",data.get("productId"));

instanceId and productId will be in the notification data

We can click the click event on the current page :

String instanceId = getIntent().getStringExtra("instanceId");
String productId = getIntent().getStringExtra("productId");


NotificationModel model = new NotificationModel();
model.setInstanceId(instanceId);
model.setProductId(productId);
model.setType(NotificationType.CLICK);

SegmentifyManager.INSTANCE.sendNotificationInteraction(model);

Information for Analytic Platform

This information is available if push information is sent to analytic platform

UtmModel utm_model = SegmentifyManager.INSTANCE.getTrackingParameters();

The UTMmodel class is as follows :

class UtmModel {
    var utm_source:String? = null
    var utm_medium:String? = null
    var utm_campaign:String? = null
    var utm_content:String? = null
}

See our sample application : Example

Example Service : Example Service