Example usage for android.app PendingIntent FLAG_CANCEL_CURRENT

List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT

Introduction

In this page you can find the example usage for android.app PendingIntent FLAG_CANCEL_CURRENT.

Prototype

int FLAG_CANCEL_CURRENT

To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.

Click Source Link

Document

Flag indicating that if the described PendingIntent already exists, the current one should be canceled before generating a new one.

Usage

From source file:com.csipsimple.service.SipNotifications.java

public void showNotificationForMissedCall(ContentValues callLog) {
    int icon = android.R.drawable.stat_notify_missed_call;
    CharSequence tickerText = context.getText(R.string.missed_call);
    long when = System.currentTimeMillis();

    if (missedCallNotification == null) {
        missedCallNotification = new NotificationCompat.Builder(context);
        missedCallNotification.setSmallIcon(icon);
        missedCallNotification.setTicker(tickerText);
        missedCallNotification.setWhen(when);
        missedCallNotification.setOnlyAlertOnce(true);
        missedCallNotification.setAutoCancel(true);
        missedCallNotification.setDefaults(Notification.DEFAULT_ALL);
    }/* w  w  w.ja va  2s .  c om*/

    Intent notificationIntent = new Intent(SipManager.ACTION_SIP_CALLLOG);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    String remoteContact = callLog.getAsString(CallLog.Calls.NUMBER);
    long accId = callLog.getAsLong(SipManager.CALLLOG_PROFILE_ID_FIELD);
    missedCallNotification.setContentTitle(formatNotificationTitle(R.string.missed_call, accId));
    missedCallNotification.setContentText(formatRemoteContactString(remoteContact));
    missedCallNotification.setContentIntent(contentIntent);

    notificationManager.notify(CALLLOG_NOTIF_ID, missedCallNotification.build());
}

From source file:me.myatminsoe.myansms.SmsReceiver.java

/**
 * Update new message {@link Notification}.
 *
 * @param context {@link Context}/*from ww w. j ava  2s .c  om*/
 * @param text    text of the last assumed unread message
 * @return number of unread messages
 */
static int updateNewMessageNotification(final Context context, final String text) {
    final NotificationManager mNotificationMgr = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final boolean enableNotifications = prefs.getBoolean(PreferencesActivity.PREFS_NOTIFICATION_ENABLE, true);
    final boolean privateNotification = prefs.getBoolean(PreferencesActivity.PREFS_NOTIFICATION_PRIVACY, false);
    final boolean showPhoto = !privateNotification
            && prefs.getBoolean(PreferencesActivity.PREFS_CONTACT_PHOTO, true);
    if (!enableNotifications) {
        mNotificationMgr.cancelAll();
        Log.d(TAG, "no notification needed!");
    }
    final int[] status = getUnread(context.getContentResolver(), text);
    final int l = status[ID_COUNT];
    final int tid = status[ID_TID];

    // FIXME l is always -1..
    if (l < 0) {
        return l;
    }

    if (enableNotifications && (text != null || l == 0)) {
        mNotificationMgr.cancel(NOTIFICATION_ID_NEW);
    }
    Uri uri;
    PendingIntent pIntent;
    if (l == 0) {
        final Intent i = new Intent(context, ConversationListActivity.class);
        // add pending intent
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        pIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    } else {
        final NotificationCompat.Builder nb = new NotificationCompat.Builder(context);
        boolean showNotification = true;
        Intent i;
        if (tid >= 0) {
            uri = Uri.parse(MessageListActivity.URI + tid);
            i = new Intent(Intent.ACTION_VIEW, uri, context, MessageListActivity.class);
            pIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

            if (enableNotifications) {
                final Conversation conv = Conversation.getConversation(context, tid, true);
                if (conv != null) {
                    String a;
                    if (privateNotification) {
                        if (l == 1) {
                            a = context.getString(R.string.new_message_);
                        } else {
                            a = context.getString(R.string.new_messages_);
                        }
                    } else {
                        a = conv.getContact().getDisplayName();
                    }
                    showNotification = true;
                    nb.setSmallIcon(PreferencesActivity.getNotificationIcon(context));
                    nb.setTicker(a);
                    nb.setWhen(lastUnreadDate);
                    if (l == 1) {
                        String body;
                        if (privateNotification) {
                            body = context.getString(R.string.new_message);
                        } else {
                            body = lastUnreadBody;
                        }
                        if (body == null) {
                            body = context.getString(R.string.mms_conversation);
                        }
                        nb.setContentTitle(a);
                        nb.setContentText(body);
                        nb.setContentIntent(pIntent);
                        // add long text
                        nb.setStyle(new NotificationCompat.BigTextStyle().bigText(body));

                        // add actions
                        Intent nextIntent = new Intent(NotificationBroadcastReceiver.ACTION_MARK_READ);
                        nextIntent.putExtra(NotificationBroadcastReceiver.EXTRA_MURI, uri.toString());
                        PendingIntent nextPendingIntent = PendingIntent.getBroadcast(context, 0, nextIntent,
                                PendingIntent.FLAG_UPDATE_CURRENT);

                        nb.addAction(R.drawable.ic_done_24dp, context.getString(R.string.mark_read_),
                                nextPendingIntent);
                        nb.addAction(R.drawable.ic_reply_24dp, context.getString(R.string.reply), pIntent);
                    } else {
                        nb.setContentTitle(a);
                        nb.setContentText(context.getString(R.string.new_messages, l));
                        nb.setContentIntent(pIntent);
                    }
                    if (showPhoto // just for the speeeeed
                            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                        try {
                            conv.getContact().update(context, false, true);
                        } catch (NullPointerException e) {
                            Log.e(TAG, "updating contact failed", e);
                        }
                        Drawable d = conv.getContact().getAvatar(context, null);
                        if (d instanceof BitmapDrawable) {
                            Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
                            // 24x24 dp according to android iconography  ->
                            // http://developer.android.com/design/style/iconography.html#notification
                            int px = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64,
                                    context.getResources().getDisplayMetrics()));
                            nb.setLargeIcon(Bitmap.createScaledBitmap(bitmap, px, px, false));
                        }
                    }
                }
            }
        } else {
            uri = Uri.parse(MessageListActivity.URI);
            i = new Intent(Intent.ACTION_VIEW, uri, context, ConversationListActivity.class);
            pIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

            if (enableNotifications) {
                showNotification = true;
                nb.setSmallIcon(PreferencesActivity.getNotificationIcon(context));
                nb.setTicker(context.getString(R.string.new_messages_));
                nb.setWhen(lastUnreadDate);
                nb.setContentTitle(context.getString(R.string.new_messages_));
                nb.setContentText(context.getString(R.string.new_messages, l));
                nb.setContentIntent(pIntent);
                nb.setNumber(l);
            }
        }
        // add pending intent
        i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);

        if (enableNotifications && showNotification) {
            int[] ledFlash = PreferencesActivity.getLEDflash(context);
            nb.setLights(PreferencesActivity.getLEDcolor(context), ledFlash[0], ledFlash[1]);
            final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
            if (text != null) {
                final boolean vibrate = p.getBoolean(PreferencesActivity.PREFS_VIBRATE, false);
                final String s = p.getString(PreferencesActivity.PREFS_SOUND, null);
                Uri sound;
                if (s == null || s.length() <= 0) {
                    sound = null;
                } else {
                    sound = Uri.parse(s);
                }
                if (vibrate) {
                    final long[] pattern = PreferencesActivity.getVibratorPattern(context);
                    if (pattern.length == 1 && pattern[0] == 0) {
                        nb.setDefaults(Notification.DEFAULT_VIBRATE);
                    } else {
                        nb.setVibrate(pattern);
                    }
                }
                nb.setSound(sound);
            }
        }

        mNotificationMgr.cancel(NOTIFICATION_ID_NEW);
        if (enableNotifications && showNotification) {
            try {
                mNotificationMgr.notify(NOTIFICATION_ID_NEW, nb.getNotification());
            } catch (IllegalArgumentException e) {

            }
        }
    }
    //noinspection ConstantConditions
    return l;
}

From source file:eu.faircode.netguard.SinkholeService.java

private void showDisabledNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked)).setContentIntent(pi)
            .setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET)
            .setColor(ContextCompat.getColor(this, R.color.colorAccent)).setAutoCancel(true);

    NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
}

From source file:com.smarthome.deskclock.Alarms.java

/**
 * Disables alert in AlarmManger and StatusBar.
 *
 * @param id Alarm ID./*  w  w  w. j av  a 2  s  .  c o m*/
 */
static void disableAlert(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, new Intent(ALARM_ALERT_ACTION),
            PendingIntent.FLAG_CANCEL_CURRENT);
    am.cancel(sender);
    setStatusBarIcon(context, false);
    saveNextAlarm(context, "");
}

From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java

private Notification.Builder getBaseEventNotificationBuilder() {
    // clicking the notification should take the user to the app
    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // FLAG_CANCEL_CURRENT is required to make sure that the extras are including in
    // the new pending intent
    PendingIntent pendIntent = PendingIntent.getActivity(context, PUBLIC_NOTIFICATION_ID, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Notification.Builder notBuilder = new Notification.Builder(context);
    notBuilder.setContentIntent(pendIntent).setOngoing(true).setOnlyAlertOnce(true).setAutoCancel(false)
            .setSmallIcon(R.drawable.small_mono);
    return notBuilder;
}

From source file:com.github.vseguip.sweet.contacts.SweetContactSync.java

@Override
public void onPerformSync(final Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {
    Log.i(TAG, "onPerformSync()");
    // Get preferences
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mContext);
    boolean fullSync = settings.getBoolean(mContext.getString(R.string.full_sync), false);
    if (fullSync)
        mAccountManager.setUserData(account, LAST_SYNC_KEY, null);
    performNetOperation(new SugarRunnable(account, syncResult, new ISugarRunnable() {
        @Override/*w  ww . j a va  2 s  .co  m*/
        public void run() throws URISyntaxException, OperationCanceledException, AuthenticatorException,
                IOException, AuthenticationException {
            Log.i(TAG, "Running PerformSync closure()");

            mAuthToken = mAccountManager.blockingGetAuthToken(account, AUTH_TOKEN_TYPE, true);
            SugarAPI sugar = SugarAPIFactory.getSugarAPI(mAccountManager, account);
            String lastDate = mAccountManager.getUserData(account, LAST_SYNC_KEY);
            List<ISweetContact> contacts = null;
            try {
                contacts = fetchContacts(sugar, lastDate);
            } catch (AuthenticationException ex) {
                // maybe expired session, invalidate token and request new
                // one
                mAccountManager.invalidateAuthToken(account.type, mAuthToken);
                mAuthToken = mAccountManager.blockingGetAuthToken(account, AUTH_TOKEN_TYPE, false);
            } catch (NullPointerException npe) {
                // maybe expired session, invalidate token and request new
                // one               
                mAccountManager.invalidateAuthToken(account.type, mAuthToken);
                mAuthToken = mAccountManager.blockingGetAuthToken(account, AUTH_TOKEN_TYPE, false);
            }
            // try again, it could be due to an expired session
            if (contacts == null) {
                contacts = fetchContacts(sugar, lastDate);
            }
            List<ISweetContact> modifiedContacts = ContactManager.getLocallyModifiedContacts(mContext, account);
            List<ISweetContact> createdContacts = ContactManager.getLocallyCreatedContacts(mContext, account);
            // Get latest date from server
            for (ISweetContact c : contacts) {
                String contactDate = c.getDateModified();
                if ((lastDate == null) || (lastDate.compareTo(contactDate) < 0)) {
                    lastDate = contactDate;
                }
            }
            // Determine conflicting contacts
            Set<String> conflictSet = getConflictSet(contacts, modifiedContacts);
            Map<String, ISweetContact> conflictingSugarContacts = filterIds(contacts, conflictSet);
            Map<String, ISweetContact> conflictingLocalContacts = filterIds(modifiedContacts, conflictSet);

            if (modifiedContacts.size() > 0) {
                // Send modified local non conflicting contacts to the
                // server
                List<String> newIds = sugar.sendNewContacts(mAuthToken, modifiedContacts, false);
                if (newIds.size() != modifiedContacts.size()) {
                    throw new OperationCanceledException("Error updating local contacts in the remote server");
                }
                ContactManager.cleanDirtyFlag(mContext, modifiedContacts);
            }
            if (createdContacts.size() > 0) {
                List<String> newIds = sugar.sendNewContacts(mAuthToken, createdContacts, true);
                if (newIds.size() != createdContacts.size()) {
                    // something wrong happened, it's probable the user will
                    // have to clear the data
                    throw new OperationCanceledException("Error creating local contacts in the remote server");
                }
                ContactManager.assignSourceIds(mContext, createdContacts, newIds);
                ContactManager.cleanDirtyFlag(mContext, createdContacts);
            }
            // Sync remote contacts locally.
            if (contacts.size() > 0) {
                ContactManager.syncContacts(mContext, account, contacts);
            }
            // resolve remaining conflicts
            List<ISweetContact> resolvedContacts = new ArrayList<ISweetContact>();
            for (String id : conflictSet) {
                ISweetContact local = conflictingLocalContacts.get(id);
                ISweetContact remote = conflictingSugarContacts.get(id);
                if (local.equals(remote)) {
                    // no need to sync
                    resolvedContacts.add(local);
                    conflictingLocalContacts.remove(id);
                    conflictingSugarContacts.remove(id);
                } else {
                    Log.i(TAG, "Local contact differs from remote contact " + local.getFirstName() + " "
                            + local.getLastName());
                    if (local.equalUIFields(remote)) {
                        // Differed in a non visible field like the account
                        // id or similar, use server version and resolve
                        // automatically
                        resolvedContacts.add(remote);
                        conflictingLocalContacts.remove(id);
                        conflictingSugarContacts.remove(id);
                    }
                }

            }
            ContactManager.cleanDirtyFlag(mContext, resolvedContacts);
            if (conflictingLocalContacts.size() > 0) {
                // Create a notification that can launch an mActivity to
                // resolve the pending conflict
                NotificationManager nm = (NotificationManager) mContext
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                Notification notify = new Notification(R.drawable.icon,
                        mContext.getString(R.string.notify_sync_conflict_ticket), System.currentTimeMillis());
                Intent intent = new Intent(mContext, SweetConflictResolveActivity.class);
                intent.putExtra("account", account);
                SweetConflictResolveActivity.storeConflicts(conflictingLocalContacts, conflictingSugarContacts);

                notify.setLatestEventInfo(mContext, mContext.getString(R.string.notify_sync_conflict_title),
                        mContext.getString(R.string.notify_sync_conflict_message),
                        PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
                nm.notify(SweetConflictResolveActivity.NOTIFY_CONFLICT,
                        SweetConflictResolveActivity.NOTIFY_CONTACT, notify);

                throw new OperationCanceledException("Pending conflicts");
            }
            // Save the last sync time in the account if all went ok
            mAccountManager.setUserData(account, LAST_SYNC_KEY, lastDate);
        }
    }));
}

From source file:com.newcell.calltext.service.SipNotifications.java

public void showNotificationForMissedCall(ContentValues callLog) {
    int icon = android.R.drawable.stat_notify_missed_call;
    CharSequence tickerText = context.getText(R.string.missed_call);
    long when = System.currentTimeMillis();

    if (missedCallNotification == null) {
        missedCallNotification = new NotificationCompat.Builder(context);
        missedCallNotification.setSmallIcon(icon);
        missedCallNotification.setTicker(tickerText);
        missedCallNotification.setWhen(when);
        missedCallNotification.setOnlyAlertOnce(true);
        missedCallNotification.setAutoCancel(true);
        missedCallNotification.setDefaults(Notification.DEFAULT_ALL);
    }/*from   w  ww .  jav a  2s .  co m*/

    Intent notificationIntent = new Intent(SipManager.ACTION_SIP_CALLLOG);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    String remoteNumber = SipUri.getPhoneNumberFromApiSipString(callLog.getAsString(CallLog.Calls.NUMBER));
    String remoteName = callLog.getAsString(CallLog.Calls.CACHED_NAME);
    /*
       * 6/11/2014 Change missed call notification
       * 
       */
    missedCallNotification.setContentTitle(context.getText(R.string.missed_call));

    missedCallNotification.setContentText(remoteNumber);
    if (remoteName != null) {
        missedCallNotification.setContentText(remoteName);
    }
    /*
     * 
     */

    missedCallNotification.setContentIntent(contentIntent);

    notificationManager.notify(CALLLOG_NOTIF_ID, missedCallNotification.build());
}

From source file:com.embeddedlog.LightUpDroid.DeskClock.java

private boolean processMenuClick(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_item_settings:
        startActivity(new Intent(DeskClock.this, SettingsActivity.class));
        return true;
    case R.id.menu_item_help:
        Intent i = item.getIntent();/*  w  w  w. j a  va2 s.co  m*/
        if (i != null) {
            try {
                startActivity(i);
            } catch (ActivityNotFoundException e) {
                // No activity found to match the intent - ignore
            }
        }
        return true;
    case R.id.menu_item_night_mode:
        startActivity(new Intent(DeskClock.this, ScreensaverActivity.class));
    case R.id.menu_item_sync_lightuppi:
        // TODO: update LightUpPiSync to actually sync alarms and then update this bit
        return true;
    case R.id.menu_item_push_to_lightuppi:
        // TODO: update LightUpPiSync to actually push alarms and then update this bit
        return true;
    case R.id.menu_item_push_to_phone:
        // TODO: update LightUpPiSync to actually push alarms and then update this bit
        String correctString = "android:switcher:" + mViewPager.getId() + ":" + ALARM_TAB_INDEX;
        new LightUpPiSync(this, correctString).syncPushToPhone();
        return true;
    case R.id.menu_item_reset_db:
        // Delete the database
        ContentResolver cr = this.getContentResolver();
        cr.call(Uri.parse("content://" + ClockContract.AUTHORITY), "resetAlarmTables", null, null);

        // Restart the app to repopulate db with default and recreate activities.
        Intent mStartActivity = new Intent(this, DeskClock.class);
        int mPendingIntentId = 123456;
        PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity,
                PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
        System.exit(0);
        return true;
    default:
        break;
    }
    return true;
}

From source file:org.ohmage.reminders.types.location.LocTrigService.java

private void setKeepAliveAlarm(Context context) {
    Intent i = new Intent(ACTION_ALRM_SRV_KEEP_ALIVE).setPackage(context.getPackageName());

    //set the alarm if not already existing
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_NO_CREATE);

    AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE);
    if (pi != null) {
        alarmMan.cancel(pi);/*from  w w  w . j ava 2  s.co m*/
        pi.cancel();
    }

    pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

    alarmMan.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime() + SERV_KEEP_ALIVE_TIME, SERV_KEEP_ALIVE_TIME, pi);
}

From source file:de.mehrmann.sdbooster.ServiceStart.java

private void userNotification(final MmcModell card, int action) {

    String text = null;//from  w ww .  j ava2s  .c o m

    if (action == 0) {

        // new device

        text = getString(R.string.msg_service_ticker_new);

    } else if (action == 1) {

        // monitor

        text = getString(R.string.msg_service_ticker_monitor_p1) + " " + card.getName() + " "
                + getString(R.string.msg_service_ticker_monitor_p2) + " " + card.getAheadUser();

    } else if (action == 2) {

        // unmanaged device

        text = getString(R.string.msg_service_ticker_value_p1) + " " + card.getName() + " "
                + getString(R.string.msg_service_ticker_value_p2);

    } else if (action == 3) {

        // License through properties

        text = getString(R.string.dlg_license_label);

    } else if (action == 4) {

        // device failed

        text = getString(R.string.msg_kernel_cache_p1) + " " + card.getName() + " "
                + getString(R.string.msg_kernel_cache_p4);

    } else if (action == 5) {

        // setting error

        text = getString(R.string.msg_error_no_cache_all);

    } else {
        throw new RuntimeException();
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setAutoCancel(true);
    builder.setOnlyAlertOnce(true);
    builder.setContentTitle(Utils.TAG);
    builder.setContentText(text);
    builder.setWhen(System.currentTimeMillis());
    builder.setSmallIcon(R.drawable.ic_launcher);

    Intent intent = new Intent();

    if (action == 2) {

        // unmanaged device

        intent.setClass(context, SDbooster.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(Utils.SERIAL, card.getSerial());

    } else if (action == 3) {

        // License

        intent.setClass(context, SDbooster.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    } else if (action == 4) {

        // device failed

        intent.setClass(context, SDbooster.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    } else if (action == 5) {

        // setting error

        intent.setClass(context, SDbooster.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(Utils.CACHE_ALL, allSize);
    }

    PendingIntent pending = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    builder.setContentIntent(pending);

    if (useAlarmNote) {
        Database db = getDbInstance();
        builder.setSound(Uri.parse(db.getRingTone()));
    }

    Notification note = builder.build();

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    int id = 0;

    try {
        id = Integer.valueOf((int) card.getId());

    } catch (Exception e) {

        if (onBoot) {
            id = 10;
        } else if (onMonitor) {
            id = 11;
        } else {
            id = 12;
        }
    }

    // license, device failed and error setting

    if (action == 3) {
        id += 3;
    } else if (action == 4) {
        id += 4;
    } else if (action == 5) {
        id += 5;
    }

    manager.notify(id, note);
}