Push Notifications
Configure push notifications using NotifyVisitors.
1) Configure in NotifyVisitors Panel
a) Go to FCM and register your app.
b) Copy Sender Id and Server key from FCM.
c) Go to NotifyVisitors panel and from mobile push menu go to Android section inside configuration section from left side menu panel and Paste Sender Id and Server key there.
2) Configure in App
Follow the below steps, if you don't have your own Firebase Integration :
a) Download the latest config json file (google-service.json file) and paste it in your app folder in IDE.
b) Add the below permissions in App’s manifest file.
<service
android:name="com.notifyvisitors.notifyvisitors.NVFirebaseMessagingService"
android:permission="${applicationId}.notifyvisitors.custom.PERMISSION">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
c) Add the below permission in your app’s build.gradle.
apply plugin: 'com.google.gms.google-services'
OR
Perform the below function in case you have your own firebase integration:
try {
if (intent.hasExtra("nv_source")) {
String value = intent.getExtras().getString("nv_source");
if (value.equals("1")) {
if(NotifyVisitorsApi.getInstance(this).isPayloadFromNvPlatform(remoteMessage.toIntent())) {
NotifyVisitorsApi.getInstance(this).getNV_FCMPayload(remoteMessage.toIntent());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if (intent.hasExtra("nv_source")) {
val value = intent.extras!!.getString("nv_source")
if (value == "1") {
if (NotifyVisitorsApi.getInstance(this).isPayloadFromNvPlatform(remoteMessage.toIntent())) {
NotifyVisitorsApi.getInstance(this).getNV_FCMPayload(remoteMessage.toIntent())
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
3) Configure Icons --> IMPORTANT
For below Lollipop devices | For Lollipop & above devices |
Devices below lollipop shows only one icon in the push notifications, that you can configure from notifyvisitors panel. To change the default notification icon, you can replace icon sm_push.png in your app’s module app/src/main/res/drawable folder. | Devices supporting Lollipop & above shows two notifications icons i.e., small push icon & large push icon. Large push icon: It is configured from panel & is shown as main push icon. However if large push icon is not configured from panel then small push icon is shown as main push icon. Small push icon: It will be set according to android documentation (https://developer.android.com/about/versions/android-5.0-changes.html). It should be transparent, otherwise it will be shown as square white spot. |
Info
To change default small push icon, you have to add icon smpush_logo.png in your app’s module app/src/main/res/drawable_ folder.
The size of monochrome icon(i.e., small push icon) will be 200x200 in PNG format. And also follow below given steps, it is mandatory.
To get small push icon effect in your status-bar,
-
Go to Android Asset Studio.
-
Select Notification Icon Generator.
-
Select Image under Source menu ( Note: Select here your Monochrome icon).
-
Copy and paste your small push icon there on.
-
Enter its name in the “Name Menu” on the left side ( Note: Name here will be as "sm_push_logo") .
-
Download the images from the top-right-corner icon. Download it as a zip file.
-
Unzip it and paste all folders in your app.
4)Notification Preferences
Give a user the option to subscribe to a specific category of notifications, or to unsubscribe completely from push notifications.
First, you will need to define the categories in NotifyVisitors Panel. Click here to learn how and then you can implement the below code in your app.
NotifyVisitorsApi.getInstance(activityContext).pushPreferences((preferenceList (JSONArray), isUnSubscribeFromAll (boolean));
Here the parameter "isUnSubscribeFromAll" is passed as a boolean. If you pass as FALSE, then it will work as a subscribing user according to the preferenceList passed. If you pass as TRUE, then it will work as unsubscribing user according to the preferenceList you passed.
Below are some cases with examples that will help you understand the scenarios of subscribing and unsubscribing.
Case1 → Subscribe the user to all the three categories passed in the array.
JSONArray jsonArray = new JSONArray();
jsonArray.put("category1");
jsonArray.put("category2");
jsonArray.put("category3");
NotifyVisitorsApi.getInstance(activityContext).pushPreferences(jsonArray, false);
Case2 → Subscribe the user to all the categories by default.
NotifyVisitorsApi.getInstance(activityContext).pushPreferences(null, false);
Case3 → UnSubscribe the user to all the three categories passed in the array.
JSONArray jsonArray = new JSONArray();
jsonArray.put("category1");
jsonArray.put("category2");
jsonArray.put("category3");
NotifyVisitorsApi.getInstance(activityContext).pushPreferences(jsonArray, true);
Case4 → UnSubscribe the user from all the categories.
NotifyVisitorsApi.getInstance(activityContext).pushPreferences(null, true);
5) Callbacks Related to Push Notifications
Implement the callback method below if you want to receive any of the below callbacks in your app. This will provide you with a response in JSONObject format.
NotifyVisitorsApi.getInstance(this).getEventResponse(new OnEventTrackListener() {
@Override
public void onResponse(JSONObject data) {
//do your task here
}
});
Push Registered
This callback will be received whenever the user gets registered in our NotifyVisitors Dashboard. Below is the sample output which you will receive in the above callback for this case-
{
"status":"success",
"eventName":"Push_Registered",
"attributes":{
"subscriptionId":"e90RM4olWRU:APA91bGhn2dL38cpy2r7eMqqqgmctPwU9wvbomq9x1TaPO6u8aDZQoiRWu5oY3-bpPe5oBwVZkzDUK5llw1t2FNnbJ5B3fjjFyi2ojnVDRLqQIFcea6ury5_KCGpwB61iTyu0fQd2ha1"
}
}
Push Clicked
This callback will be received whenever the user clicks on push notification received from NotifyVisitors Dashboard. In this callback, you will also get all attributes associated with the click type of the push notification. Below is the sample output which you will receive in the above callback for this case-
{
"status":"success",
"eventName":"Push_Clicked",
"attributes":{
"action_params":{
"KEY4":"989"
},
"notification_id":"108219"
}
}
Updated 23 days ago