4. Click Counts for Mobile Push Notifications
Before you begin, make sure you’ve completed these steps:
- Setting up Integration Points for Android App
- Retrieving Firebase Keys for an Android App
- Adding the SDK to Your App
- Initializing the SDK
- Sending Push Notifications Using Firebase or Sending Push Notifications Using Huawei
By the end of this guide, you should see the following result:
You can send a mobile push notification from Mindbox and the target device will display it. When you tap the notification, the status in your project’s UI changes to "Clicked."
To check that clicks are being detected, please use this guide.
1. Submitting push notification click counts
Insert the Mindbox.onPushClicked
method call in the activities you specified in the onMessageReceived
method earlier.
You should call Mindbox.onPushClicked
through 2 callbacks: onNewIntent
and onCreate
.
import cloud.mindbox.mobile_sdk.*
class MainActivity : AppCompatActivity() {
private fun processMindboxIntent(intent: Intent?) {
// Adding a push-related click event
intent?.let { Mindbox.onPushClicked(this, it) }
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
processMindboxIntent(intent)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
processMindboxIntent(intent)
// ...
}
// ...
}
Note that Mindbox.onPushClicked
returns true
if the SDK identifies the intent and processes it properly. Otherwise, the method returns false
.
2. App navigation
A click invokes the activity you specified in the push notification settings. To process any other data from a push notification, use the getUrlFromPushIntent
and getPayloadFromPushIntent
methods.
val pushUrl = Mindbox.getUrlFromPushIntent(intent)
val payload = Mindbox.getPayloadFromPushIntent(intent)
Check your results:
You should now be able to send a push notification from Mindbox that will be displayed on your target device. When you tap the notification, its status should change to "Clicked" in the interface.
Updated about 1 year ago