Android Push Notification
Introduction¶
Create a project as follows : Firebase Console
Select Android icon :
Once you've entered your package name, put the google-service.json file in the root directory as shown in the image download step :
Add the following codes to your project-level build.gradle file and app-level file as shown in the picture :
For Android 13+ You'll need to add following part to your MainActivity class
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.POST_NOTIFICATIONS),1001)
}
}
Segmentify Configuration Step¶
Please refer to this page for Segmentify configuration process.
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
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