活动通知



我的通知非常好,但是我的问题是,当我单击通知中心中的通知时,它不会启动我的活动。

基本上,单击我的通知之后,它的开放性主动脉,但我想从应用程序中打开其他页面。

当我的应用在前景并通知到达其开放的完美页面时

所以请告诉我我该怎么办..?

 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());
    }

在您的通知有效载荷中,您需要click_action属性才能单击通知。

请检查Firebase文档的此部分。

另外,当您定义click_action属性时,您还需要在要启动的活动的<intent-filter>中相应的<action>属性。

本视频以相当详细的方式解释它。

不过,请注意,如果您是从Firebase控制台发送通知,则无法设置click__action属性。仅当您从自己的管理员服务器发送通知或使用Firebase Cloud函数时,才可以这样做。

最后,在启动的活动中,您可以使用getIntent()获得其余的通知数据。查看此答案以获取有关如何执行此操作的更多详细信息。

最新更新