onMessageOpened
Callback invoked when a user taps on a notification.
Override this method to handle notification open events, such as tracking analytics, updating application state, or triggering custom logic. This callback is called after the activity is launched but provides an opportunity to perform additional processing.
This method is called on the main thread after startActivityForPushMessage. Example:
protected void onMessageOpened(PushMessage message) {
// Track notification open in analytics
String campaignCode = message.getCustomData().getString("campaign_code");
Analytics.track("push_opened", campaignCode);
// Update user engagement score
SharedPreferences prefs = getApplicationContext()
.getSharedPreferences("user_stats", Context.MODE_PRIVATE);
int openCount = prefs.getInt("push_open_count", 0);
prefs.edit().putInt("push_open_count", openCount + 1).apply();
// Log for debugging
Log.d("PushNotifications", "User opened: " + message.getMessage());
}
Content copied to clipboard
Parameters
message
the push message that was opened, containing notification data and custom payload