Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notification manager help

I m currently looking into android notification. Is there any way to show all the notification from an application as a single one with the number in android notifications window. Clicking on this will redirect the user to a view in the application with separate notifications. Also Is there any way to set the activity for each notifications so that the user will be redirected to the appropriate activity based on the notification clicked.

like image 581
Dijo David Avatar asked Nov 27 '25 03:11

Dijo David


1 Answers

You could attach a custom layout to your notification, which contains a counter. And when event occurs increase the counter and update the notification. Similar like in example below:

   Notification notification = new Notification(R.drawable.logo, name,    System.currentTimeMillis());

   RemoteViews contentView = new RemoteViews(appContext.getPackageName(), R.layout.custom_layout );

   contentView.setTextViewText(R.id.notification_text, Counter);

notification.contentView = contentView;

To attach an activity to the notification:

        Intent notificationIntent = new Intent(appContext, MyActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(...);
        notificationIntent.putExtras( bundle );
        notificationIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);           

        PendingIntent contentIntent = PendingIntent.getActivity( appContext, (int)System.currentTimeMillis(), notificationIntent, 0 );
        notification.contentIntent = contentIntent;

Hope it will help.

like image 166
ackio Avatar answered Nov 29 '25 17:11

ackio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!