通知单击不会打开所需的活动

时间:2017-08-26 13:51:40

标签: android firebase android-pendingintent

在我的应用中,根据显示的通知,必须打开相应的活动。简而言之,有多个未决意图。即使分配了活动,点击通知也会转到启动活动,而不是所需的活动。

    private void sendNotification(final String notificationTitle, final String notificationBody) {
            if (notificationTitle.equals("Mango")) {

                        Intent intent = new Intent(MyFirebaseMessagingService.this, Mango.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        pendingIntent(notificationTitle, notificationBody, intent, INT = 100);

                    } else if (notificationTitle.equals("Orange")) {
                        Intent intent = new Intent(MyFirebaseMessagingService.this, Orange.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        pendingIntent(notificationTitle, notificationBody, intent, INT = 1);
                    }


 public void pendingIntent(String notificationTitle, String notificationBody, Intent intent , final int INT){

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addNextIntentWithParentStack(intent);

        PendingIntent pendingIntent=stackBuilder.getPendingIntent(INT, PendingIntent.FLAG_CANCEL_CURRENT);

       // PendingIntent pendingIntent = PendingIntent.getActivity(MyFirebaseMessagingService.this, INT, intent,PendingIntent.FLAG_UPDATE_CURRENT);
        final NotificationCompat.Builder notificationBuilder;
        notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                .setAutoCancel(true)   //Automatically delete the notification
                .setSmallIcon(R.mipmap.ic_launcher) //Notification icon
                .setContentIntent(pendingIntent)
                .setContentTitle(notificationTitle)
                .setContentText(notificationBody);
        mAuth = FirebaseAuth.getInstance();
        firebaseUser=mAuth.getCurrentUser();

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(INT, notificationBuilder.build());

    }

                }

0 个答案:

没有答案