On tapping the push notifications user is usually redirected to the app, but some users do not get redirected to the app on tapping the push notifications.
For them the notification is simply dismissed and the app is not launched.
It might be a case, where these users have not opened the app for a long time, but would that affect the redirection to app behavior? I have also tried to reproduce this by forcing the device in doze mode, but I still get redirected to the app.
Can someone please help me solve this issue, where the user sometimes is not redirected to the app on tapping of the push notification.
This is my AndroidManifest.xml
<service
android:name=".screens.fcm.MyFirebaseMessagingService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
and this is my FirebaseMessagingService
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent = new Intent(this, HomeActivity.class);
String notificationType = (remoteMessage.getData().get("notification_type") != null) ?
messageBody.getData().get("notification_type") : "";
if ((notificationType.equalsIgnoreCase("main")))
intent.putExtra("type", "main");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
RemoteMessage.Notification notification = remoteMessage.getNotification();
String notificationTitle = notification != null ? notification.getTitle() : "";
String notificationMessage = notification != null ? notification.getBody() : "";
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, "")
.setSmallIcon(R.drawable.notification)
.setContentTitle(notificationTitle)
.setContentText(notificationMessage)
.setAutoCancel(true)
.setGroup(GROUP_KEY_HOME_NOTIFICATIONS)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("",
"Channel1",
NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}