Instructions for connecting mobile push notifications (Android)

To connect mobile push notifications you need to request a library from your account manager. Or write to us at experts@enkod.io

1. Connecting the module

To add a module to your project, you need to place the EnkodPushLibrary folder on the same level as the app module.

In settings.gradle add:

include ':EnkodPushLibrary'    

For this library minSdkVersion = 23

Add to manifest in AndroidManifest:

<uses-permission android:name="android.permission.INTERNET" />

In AndroidManifest in application add:

android:usesCleartextTraffic="true"  

2. Initialisation of dependencies

1. A library module dependency should be added to the app module level gradle file:

implementation project(path: ':EnkodPushLibrary') 

2. An FCM dependency should be added to the app module level gradle file (tested on version 23.0.5):

implementation 'com.google.firebase:firebase-messaging:23.0.5'  

3. You should also add the Google services plugin:

id 'com.google.gms.google-services'  // Google Services plugin 

4. Google services dependency should be added to the application level file gradle:

dependencies {
...
    classpath 'com.google.gms:google-services:4.3.5'
...
}   

5. Google repository should be added to the gradle of the application level file:

repositories {
...
    google()
...
} 

6. To initialise the library, you must call the builder in your Application class and specify the parameters:

EnkodPushLibrary.Builder()
    .setOnTokenListener{}
    .setOnMessageReceiveListener { showToast(it.messageId) }
    .setOnDeletedMessageListener { showToast("message deleted") }
    .setOnDynamicLinkClickListener { string-> }
    .setOnProductCallBackListener { }
    .setOnErrorListener { errorToast(it) }
    .setOnBaseUrlCheckerListener {  }
    .setOnPushClickListener { bundle: Bundle, str: String-> }
    .build(applicationContext, «account») 

where account - system name of your account in enKod (ask your personal manager)

Methods and conditions of triggering:

  • setOnTokenListener - when token is updated, also it will be called during initialisation and token will be passed to it for further processing
  • setOnMessageReceiveListener - when a new push notification is received on the device, this very message is passed to it
  • setOnDeletedMessageListener - when onDeletedMessages is called in the push control service, according to the https://firebase.google.com/docs/cloud-messaging/android/receive#override-ondeletedmessages
  • setOnDynamicLinkClickListener - when opening a push notification with a dynamic link, this link is passed to it
  • setOnProductCallBackListener - method which is triggered when methods for working with products are executed
  • setOnErrorListener - method that triggers when errors occur when accessing the server
  • setOnBaseUrlCheckerListener - method for processing BaseUrl
  • setOnPushClickListener - when opening a push notification
  • build - initialisation of the library and all its variables, context and client name should be passed to it

You can also call each of the above methods separately on the library after initialisation.

  • subscribeToPush и unsubscribeFromPush - methods for subscribing and unsubscribing from pushes, after calling them a request will be sent to the server.

3. Processing a push on a push

When the application is opened via a push, the activation specified in the push is opened, it sends a request to the server that the push has been opened and the method will be called .setOnPushClickListener {if it was a dynamic link, the method will be called additionally. setOnDynamicLinkClickListener { str-> }%

4. Account logout and registration

To stop receiving notifications when logging out of an account, you must use the logOut() method, which will delete the current token and clear the Firebase instance. To resume receiving notifications, you must call the createToken() method to create a new token.

To use a custom deep link handler, you must pass a custom handler to setOnDynamicLinkClickListener { } when initialising the library. Otherwise, the click will be handled by the library's built-in methods.

6. Message model

"notification": {
    "click_action":".OnOpenActivity",
    "body":"Body of Your Notification",
    "icon":"ic_launcher_background",
    "title":"Title of Your Notification",
    "color":"#FFEE1000",
    "image":"https://picsum.photos/200/300",
},
"data": {
    "intent":"0",
    "url":"https://www.gsrikar.com/2018/12/read-metadata-from-andriod-manifest.html",
    "priority":"0",
    "led":"#FFEE1000",
    "led_on":"300",
    "led_of_ms":"100",
    "hasVibro":"true",
    "hasSound":"true",
    "channel":"enkod_lib_59",
    "personId":20,
    "messageId":10,
    "intent1":"1",//актуально для кнопок в уведомлении
    "url1":"testapp://screen1",//актуально для кнопок в уведомлении
    "label1":"Text in button1",//актуально для кнопок в уведомлении
}                      

Data value

%"click_action" Activity that handles clicks should be specified OnOpenActivity
%"body" push body text
"icon" icon resource name
"title" push title
"colour" fluff icon colour
%"image" image url
%"intent" the action that will be performed when the push button is clicked:
  • "0" - the application will be opened and a dynamic link will be passed to it for further processing
  • "1" - opening the link in the browser
  • "any other value" - application will be opened
"url" the link is dynamic or to be opened in a browser
%"priority" Push priority, takes values:
  • "-2" - PRIORITY_MIN
  • "-1" - PRIORITY_LOW
  • "0" - PRIORITY_DEFAULT
  • "1" - PRIORITY_HIGH
"led" indicator colour
%"led_on": "300" indicator on time
"led_of_ms":"100" indicator off time
"hasVibro":"true" has vibration or not
"hasSound":"true" has sound or not
"channel":"enkod_lib_59" channel id
Last modified: 2023.12.13 10:37 by Anastasia Aniskova