SDK Version Update Guide
Update Exponea Android SDK in your app to a new version
This guide will help you upgrade your Exponea SDK to the new version.
Update from version 2.x.x to 3.x.x
Updating Exponea SDK to version 3 or higher requires you to make some changes related to push notifications.
Changes Regarding FirebaseMessagingService
In order to keep the SDK as small as possible and avoid including libraries that are not essential for it functionality, an implementation of FirebaseMessagingService
is no longer included in the SDK. As a result, the SDK no longer has a dependency on the Firebase library.
You are required to make the following changes in your application:
If you are already using your own service that extends FirebaseMessagingService
-
You must change the second parameter when calling the
Exponea.handleRemoteMessage
method. It no longer accepts a FirebaseRemoteMessage
but now accepts the message data directly instead. -
Instead of calling
Exponea.trackPushToken
when a new token is obtained, callExponea.handleNewToken
with the application context. This method will track the new token to the Engagement platform. If the SDK is not initialized at the moment of invokation, it will persist the token and track it later, after SDK initialization.
If you do not have your own service and you were relying on the implementation included in the SDK
You must implement FirebaseMessagingService
in your application since the SDK no longer provides an implementation.
- Create a service that extends
FirebaseMessagingService
- Call
Exponea.handleRemoteMessage
when a message is received - Call
Exponea.handleNewToken
when a token is obtained - Register this service in your
AndroidManifest.xml
class MyFirebaseMessagingService : FirebaseMessagingService() {
private val notificationManager by lazy {
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
}
override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
Exponea.handleRemoteMessage(applicationContext, message.data, notificationManager)
}
override fun onNewToken(token: String) {
super.onNewToken(token)
Exponea.handleNewToken(applicationContext, token)
}
}
<service android:name="MyFirebaseMessagingService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Changes Regarding Notification Trampolining
Android (from version 12) restricts starting any Intent
from a notification action indirectly. This means an activity can no longer be started from a service or receiver. In version 3.0.0 of the SDK, we made changes to comply with these rules. The SDK starts all notification action Intent
s directly (opening the app, opening a web browser, opening a deep link). Previous versions required creating a BroadcastReceiver
to handle an Intent with the action com.exponea.sdk.action.PUSH_CLICKED
and start the app on the application side. You must remove this code since this receiver acts as a notification trampoline, which, when targeting Android S and above, can cause the app to crash. You can safely remove this code; opening your Launcher Activity on a push click is now handled by the SDK.
If you still need to do some processing in your app, when a notification action is clicked, you can continue to use the receiver for that as long as you don;t start any intent from it if you are targeting Android 12 and higher.
Broadcast for
com.exponea.sdk.action.PUSH_CLICKED
,com.exponea.sdk.action.PUSH_DEEPLINK_CLICKED
andcom.exponea.sdk.action.PUSH_URL_CLICKED
actions was removed by mistake in version 3.0.0 and added back in 3.0.1. Please update directly to this patch, if you need to use it.
💻 Usage
Registration in AndroidManifest.xml
<receiver
android:name="MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.exponea.sdk.action.PUSH_CLICKED" />
<action android:name="com.exponea.sdk.action.PUSH_DEEPLINK_CLICKED" />
<action android:name="com.exponea.sdk.action.PUSH_URL_CLICKED" />
</intent-filter>
</receiver>
Receiver class
class MyReceiver : BroadcastReceiver() {
// React on push action click
override fun onReceive(context: Context, intent: Intent) {
// Extract push data
val data = intent.getParcelableExtra<NotificationData>(ExponeaExtras.EXTRA_DATA)
val actionInfo = intent.getSerializableExtra(ExponeaExtras.EXTRA_ACTION_INFO) as? NotificationAction
val customData = intent.getSerializableExtra(ExponeaExtras.EXTRA_CUSTOM_DATA) as Map<String, String>
// Process push data as you need
}
}
Changes in Public API
Exponea SDK no longer has a dependency on the Firebase library. For this reason, the signature of public methods that accepted a Firebase RemoteMessage
has changed. These methods now accept message data directly instead. You can obtain them by calling getData()
on the RemoteMessage
object.
fun handleRemoteMessage(
applicationContext: Context,
message: RemoteMessage?,
manager: NotificationManager,
showNotification: Boolean = true
): Boolean
has changed to
fun handleRemoteMessage(
applicationContext: Context,
messageData: Map<String, String>?,
manager: NotificationManager,
showNotification: Boolean = true
): Boolean
and
fun isExponeaPushNotification(message: RemoteMessage?): Boolean
has changed to
fun isExponeaPushNotification(messageData: Map<String, String>?): Boolean
Invoking
Exponea.handleNewToken
,Exponea.handleNewHmsToken
, andExponea.handleRemoteMessage
is allowed before SDK initialization in case it was initialized previously. In such a case, these methods will track events with the configuration of the last initialization. Please consider initializing the SDK inApplication::onCreate
to ensure a fresh configuration is applied in case of an update of your application.
Updated 3 months ago