Android Notification Manager Assistant

I am currently viewing an Android notification. Is there a way to show all notifications from the application as one with a number in the Android notification window. Clicking on this will redirect the user to the presentation in the application with separate notifications. Is there also a way to set activity for each notification so that the user is redirected to the corresponding action based on the clicked notification.

+3
source share
1 answer

You can attach a custom layout to your notification , which contains a counter. And when the event happens, increase the counter and refresh the notification . As in the 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 associate an action with a 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 this helps.

+6
source

All Articles