Pending Intent Not Working, Notification Does Not Open Activity

Viewed 2410

Hello I have the following function that displays notifications in my app, however I suddenly started having an issue where when I click a notification it does not take me to the activity I specified in .setContentIntent(), this is my code:

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void getNotifications() {
    ArrayList<com.xxxxxx.app234929.models.Notification> notifications = mNotificationsTable.get();

    int requestId = (int) System.currentTimeMillis();
    Intent notificationsIntent = new Intent(getApplicationContext(), NotificationsActivity.class);
    notificationsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), requestId,
            notificationsIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.ic_stat_mtgh_notification)
            .setColor(getResources().getColor(R.color.colorPrimary))
            .setContentTitle("xxxxxx")
            .setContentText("You have "+(notifications.size() > 1 ? "new updates" :"a new update"))
            .setNumber(notifications.size())
            .setContentIntent(intent)
            .setDefaults(Notification.DEFAULT_VIBRATE |
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS))
            .setBigContentTitle("xxxxxx");

    for (int i=0; i < notifications.size(); i++) {
        inbox.addLine(notifications.get(i).getMessage());
    };

    Notification notification = inbox.build();

    NotificationManager notificationManager = (NotificationManager) getApplicationContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, notification);
}

I've googled a lot of solutions and tried them but none of them worked for me so now I do not know what I am doing wrong here.

1 Answers
Related