Mobile Apps – technical documentation for Android

Requirements

Initialisation

Create an instance of GetResponseMobileSDK with data created in the GetResponse App.

val grMobileSDK =
   GetResponseMobileSDK(
       this,
       applicationId,
       entryPoint,
       secretKey,
       notificationIcon,
       channelsConfig (optional),
       enableDebug (optional)
   )

Parameters: 

  • applicationId, entryPoint, secretKey – Data provided in GetResponse App
  • notificationIcon – Notification Icon Resource ID 
  • channelsConfig – (optional) list of notification channels for Android SDKs that support it. This parameter is optional, and SDK will create channels for you if they don’t exist.
    It will also create a new channel if channel_id provided in the notification created on the GetResponse website is missing.
  • enableDebug – this flag enables logs for http calls.

Messaging service – handle Incoming Push Message

This point assumes that Firebase Messaging is configured and there is a service extending FirebaseMessagingService 

Inject GetResponseMobileSDK

in the MessagingService and provide what class is your app entry point. 

MessagingService:


override fun onMessageReceived(remoteMessage: RemoteMessage) {
   super.onMessageReceived(remoteMessage)
   val pushConsumed = grMobileSDK.handleIncomingPush(
       remoteMessage.data,
       MainActivity::class.java
   )
   Log.d(TAG, if (pushConsumed) "GetResponse notification" else "Not a GetResponse notification")
}

handleIncomingPush method will return boolean value. True if it detects a message sent by GetResponse, and false in all other cases.

Update Push Notification Consent: 

In order to support fcmToken changes, app needs to register for this in onNewToken callback (https://firebase.google.com/docs/cloud-messaging/manage-tokens#retrieve-and-store-registration-tokens

override fun onNewToken(token: String) {
   super.onNewToken(token)
   Log.d(TAG, "Refreshed token: $token")
   scope.launch {
       grMobileSDK.consent(
           languageCode,
           externalId,
           email,
           token
       )
   }
}

Activity settings

The next part of the setup is setting Android Activity component to register fcmToken in GetResponse platform and to handle incoming Intent after interaction with Notification. 

Register for push notification in GetResponse

After obtaining fcmToken from Firebase – application has to send consent using GetResponseMobileSDK. This is typically done using the following method:

suspend fun connectMessaging() {
   val token = FirebaseMessaging.getInstance().token.await()
   grSdk.consent(languageCode, externalId, email, token)
}

Consent request

In order to register a user device in the GetResponse platform app, you need to send a consent request. This is done using the suspending method – consent

Parameters: 

  • languageCode – (optional) use this parameter to provide information about the language in which the user uses the app
  • externalId – (optional) can be used to connect users from external services in the GetResponse database. 
  • email – (optional) this parameter will link push notification user with GetResponse subscriber
  • token – fcmToken provided by Firebase Messaging

This method should be run every time your app starts – this ensures that only actual tokens used by users are stored in GetResponse. 

Handle Notification interactions

In order to fully use the capabilities of our SDK, we provide a method that should be used after receiving intent when the user interacts with notification.

In the onCreate method of the Activity previously provided in handleIncomingPush parameters, add this line to read message data and count statistics for push notification:

class MainActivity : ComponentActivity() {
   …
   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       val incomingNotification = grSdk.handleIncomingNotification(this, intent)

Return of this function is a list of parameters provided in the Administration Panel while sending Push Message. 

When the application is in the background, delivery statistics will be counted only after clicking on the notification.

Delete consent

This method should be run whenever you think GetResponse should stop sending messages to specific device
(primary use case is before the user logs out from the app).

scope.launch {
   grSdk.deleteConsent()
}

Popular resources