При нажатии на уведомление fcm не go к действию spesifi c, вводящему намерение - PullRequest
1 голос
/ 18 марта 2020

Я работаю над приложением android с уведомлением fcm. Я обрабатываю уведомление и ставлю намерение с указанием c классов для каждого типа уведомления. но когда я нажимаю на уведомление, это приводит меня к основной деятельности (которую я не хочу и не помещаю в намерение), я не знаю, что я пропустил !!

Это мой код:

    private void sendNotification(String messageBody, String title) {
        Intent intent;
        EventObject eventObject = new EventObject(0,"","");


        if(type.equals("order_pending") ){
            intent = new Intent(this, orderDetailsActivity.class)
                    .putExtra("orderId", order_id);
            eventObject = new EventObject(Integer.parseInt(order_id),"order_pending", messageBody);
        }

        else if( type.equals("order_declined")) {
            intent = new Intent(this, orderDetailsActivity.class)
                    .putExtra("orderId", order_id);
            eventObject = new EventObject(Integer.parseInt(order_id) ,"order_declined", messageBody);

        }

        else {
            intent = new Intent(this, MainActivity.class);
            eventObject = new EventObject(1,"Activate Agent",messageBody);
        }


        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        String channelId = getString(R.string.default_notification_channel_id);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.drawable.logo)
                        .setContentTitle(title)
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        int f =0;
        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            NotificationChannel channel = new NotificationChannel(channelId,
                    "Channel human readable title",
                    NotificationManager.IMPORTANCE_HIGH);
            notificationManager.createNotificationChannel(channel);
        }

        EventBus.getDefault().post(eventObject);


            notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
     }
...