This demo will show how to

1. Create and add a new Notification,
2. How many notifications are active in the current Application?
3. Delegate method for Notification Deletion.


For Adding a Notification we can use the following snippet.

// Create a Notification and notify the system.
final Notification.Builder builder = new Notification.Builder(getActivity())

final Notification notification =;
mNotificationManager.notify(++mNotificationId, notification);


For reading the number of currently Active notifications we can use

// Query the currently displayed notifications.
final StatusBarNotification[] activeNotifications = mNotificationManager
final int numberOfNotifications = activeNotifications.length;


To know when a Notification is deleted.

 // Create a PendingIntent to be fired upon deletion of a Notification.
 Intent deleteIntent = new Intent(ActiveNotificationActivity.ACTION_NOTIFICATION_DELETE);
 mDeletePendingIntent = PendingIntent.getBroadcast(getActivity(),
                2323 /* requestCode */, deleteIntent, 0);

Infolinks (Activity when notification is clicked).


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.PersistableBundle;

public class ActiveNotificationActivity extends MainActivity {

    private ActiveNotificationFragment mFragment;

    protected static final String ACTION_NOTIFICATION_DELETE
            = "";

    private BroadcastReceiver mDeleteReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            if (mFragment == null) {

    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);

    private void findFragment() {
        mFragment = (ActiveNotificationFragment) getSupportFragmentManager()

    protected void onResume() {
        registerReceiver(mDeleteReceiver, new IntentFilter(ACTION_NOTIFICATION_DELETE));

    protected void onPause() {

You can download the complete source Code from here.



Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.