Pavel Petrashov
Pavel Petrashov

Reputation: 205

A few questions about the notification

I have a few questions. 1. when I send a notice that it replaces the old. I need to increment a counter notification.

  1. how to do that when you click on the notification to open certain fragment?

    private static void generateNotification(Context context, String message,int type) {

        String title = null;
        int icon = R.drawable.ic_stat_gcm;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);
        title = context.getString(R.string.app_name);
        Intent notificationIntent = new Intent(context, MainActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    
    }
    

Upvotes: 0

Views: 41

Answers (2)

Md Abdul Gafur
Md Abdul Gafur

Reputation: 6201

Calculate the number if notification come before user last open n and increase the counter by this way.

notification.number += count(here is number of notification);`

Thanks

Upvotes: 0

Marcin Orlowski
Marcin Orlowski

Reputation: 75629

how to do that when you click on the notification to open certain fragment?

You cannot open Fragment directly. You need to open Activity that then will use that Fragment

Upvotes: 1

Related Questions