Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

after tapping on notification app not launch in android 12 version?

My app uses FCM for notifications. When the user taps the notification on Android 12, the application does not launch, whereas it does on lower versions.

The FirebaseMessagingService code is below.

private RemoteViews getCustomDesign(String title, String message) {
    RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_collapsed);
    remoteViews.setTextViewText(R.id.collapsed_notification_title, title);
    remoteViews.setTextViewText(R.id.collapsed_notification_info, message);
    return remoteViews;
}

@SuppressLint("UnspecifiedImmutableFlag")
public void showNotification(Context context, NotificationData data) {
    Intent intent = new Intent(context, MainActivity.class);
    String channel_id = "Default";
    intent.putExtra(NOTIFICATION_ID, data.getNotificationId());
    intent.putExtra(LEAD_ID, data.getLeadId());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    PendingIntent notifyPendingIntent;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyPendingIntent = PendingIntent.getActivity(context,
                0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);

    }else {
        notifyPendingIntent = PendingIntent.getActivity(context,
                0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channel_id)
            .setSmallIcon(R.drawable.logoo)
            .setAutoCancel(true)
            .setOnlyAlertOnce(true)
            .setContentIntent(notifyPendingIntent)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
            .setCustomContentView(getCustomDesign(data.getTitle(), data.getMessage()));
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(channel_id, "Default channel", NotificationManager.IMPORTANCE_HIGH);
        notificationManager.createNotificationChannel(notificationChannel);
    }

    notificationManager.notify(0, builder.build());
}
like image 541
Mahesh Jadhav Avatar asked Sep 06 '25 02:09

Mahesh Jadhav


1 Answers

Please check your com.google.firebase:firebase-messaging version in build.gradle After hours of searching I found out that the Firebase Team fixed it in v22.0.0 https://firebase.google.com/support/release-notes/android#messaging_v22-0-0

like image 142
FariJan Avatar answered Sep 10 '25 03:09

FariJan