0

My notifications fires very well, but my problem is that, when I click on notification in Notification Center, it does not start my Activity which one is open for app.

Basically, after clicking on my notification its open Mainactivity but i want to open some another pages from my application.

when my app is in foreground and notification arrived its open perfect page but when application is not in foreground it's open Mainactivity

so please tell me what should i can do for that..?

 private void sendNotification(String body) {

        if (body.equals("Image Upload Successfully")){
            intent= new Intent(this, Image_Gallery.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        }else if (body.equals("Video Upload Successfully")){

            intent = new Intent(this, Video_Gallary.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }else if (body.equals("Home Work Are Uploaded")){

            intent = new Intent(this, HomeWork.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }else if (body.equals("Daily Work Are Uploaded")){

            intent = new Intent(this, DailyDairy.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }else if (body.equals("Upcomming Holiday")){

            intent = new Intent(this, Events.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }else if (body.equals("New Event Are Uploaded")){

            intent = new Intent(this, Events.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }



        PendingIntent pendingIntent = PendingIntent.getActivity(this, not_nu, intent, PendingIntent.FLAG_ONE_SHOT);
        //Set sound of notification
        Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Notificaton")
                .setContentText(body)
                .setAutoCancel(true)
                .setVibrate(v)
                .setSound(notificationSound)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(not_nu , notifiBuilder.build());
    }
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141

1 Answers1

0

In your notification payload, you need the click_action attribute for the notification to be clickable.

Please check this section of the Firebase docs.

Also, when you define the click_action attribute, you will also need a corresponding <action> attribute in the <intent-filter> of the activity that you wish to launch.

This video explains it in quite a detailed manner.

Though, please note that you can not set the click__action attribute if you're sending notifications from the Firebase Console. You can only do so if you send a notification from your own Admin server or using Firebase Cloud Functions.

Lastly, in the activity that is launched, you can obtain the rest of the notification data using getIntent(). Check out this answer for more details on how to do that.

Rohan Stark
  • 2,346
  • 9
  • 16