Example usage for android.app NotificationManager cancelAll

List of usage examples for android.app NotificationManager cancelAll

Introduction

In this page you can find the example usage for android.app NotificationManager cancelAll.

Prototype

public void cancelAll() 

Source Link

Document

Cancel all previously shown notifications.

Usage

From source file:org.authme.android.core.AuthListFragment.java

public void doNotificationClear() {

    /* Clear notifications */

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager notificationManager = (NotificationManager) MasterPassword.getInstance()
            .getApplicationContext().getSystemService(ns);

    notificationManager.cancelAll();
    Log.v(TAG, "Cleared all C2DM notifications");

}

From source file:mf.stickybit.android.trackergps.LoginActivity.java

public void checkLogin(boolean isLogin) {
    if (isLogin) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancelAll();
        final Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(Intent.ACTION_MAIN);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        Notification notification = new NotificationCompat.Builder(this)
                .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0))
                .setSmallIcon(R.drawable.trackergps_icon)
                .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.trackergps_icon))
                .setTicker("TrackerGPS").setWhen(System.currentTimeMillis()).setAutoCancel(false)
                .setContentTitle("TrackerGPS esta ejecutandose").setContentText("A la espera...").build();
        notification.flags |= Notification.FLAG_NO_CLEAR;
        notificationManager.notify(0, notification);

        moveTaskToBack(true);//from   w ww.  j  ava 2  s  .  c om
    } else {
        if ((getCantidadFails() == (getResources().getInteger(R.integer.login_max_retry)))) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Fallo "
                    + String.valueOf(
                            (int) getApplicationContext().getResources().getInteger(R.integer.login_max_retry))
                    + " veces al iniciar sesin.")
                    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            finish();
                        }
                    });
            builder.show();
        } else {
            clear();
            mPasswordView.setError(getString(R.string.error_incorrect_password));
            mPasswordView.requestFocus();
        }

    }
}

From source file:com.wondereight.sensioair.gcm.GcmMain.java

public void removeLocalNotification(Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    //notificationManager.cancel( 0 );
    notificationManager.cancelAll();
}

From source file:ro.weednet.contactssync.syncadapter.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//  w w  w .  j a  v  a  2  s.  com
    String authtoken = null;
    try {
        //   ContactManager.setAccountContactsVisibility(getContext(), account, true);
        ContactsSync app = ContactsSync.getInstance();

        if (app.getSyncWifiOnly() && !app.wifiConnected()) {
            throw new OperationCanceledException("not on wifi");
        }

        authtoken = mAccountManager.blockingGetAuthToken(account, Constants.AUTHTOKEN_TYPE,
                NOTIFY_AUTH_FAILURE);
        if (authtoken == null) {
            throw new AuthenticationException();
        }

        final long groupId = ContactManager.ensureGroupExists(mContext, account);
        final Uri rawContactsUri = RawContacts.CONTENT_URI.buildUpon()
                .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
                .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();

        List<RawContact> localContacts = ContactManager.getLocalContacts(mContext, rawContactsUri);

        if (app.getFullSync()) {
            ContactManager.deleteContacts(mContext, localContacts);
            localContacts.clear();
            app.clearFullSync();
        }

        NetworkUtilities nu = new NetworkUtilities(authtoken, mContext);
        List<RawContact> rawContacts = nu.getContacts(account);

        List<RawContact> syncedContacts = ContactManager.updateContacts(mContext, account, rawContacts, groupId,
                app.getJoinById(), app.getSyncAllContacts());

        ContactManager.deleteMissingContacts(mContext, localContacts, syncedContacts);

        if (app.getJoinById()) {
            ContactManager.addJoins(mContext, account, rawContacts);
        }

        if (app.getSyncType() == ContactsSync.SyncType.HARD) {
            localContacts = ContactManager.getLocalContacts(mContext, rawContactsUri);
            ContactManager.updateContactDetails(mContext, localContacts, nu);
        } else if (app.getSyncType() == ContactsSync.SyncType.MEDIUM) {
            List<RawContact> starredContacts = ContactManager.getStarredContacts(mContext, rawContactsUri);
            ContactManager.updateContactDetails(mContext, starredContacts, nu);
        }

        NotificationManager mNotificationManager = (NotificationManager) getContext()
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancelAll();

    } catch (final AuthenticatorException e) {
        Log.e(TAG, "AuthenticatorException", e);
        syncResult.stats.numParseExceptions++;
        showNotificationError("Error connecting to facebook");
    } catch (final OperationCanceledException e) {
        Log.e(TAG, "OperationCanceledExcetpion", e);
    } catch (final IOException e) {
        Log.e(TAG, "IOException", e);
        syncResult.stats.numIoExceptions++;
        showNotificationError("Error connecting to facebook");
    } catch (final AuthenticationException e) {
        Log.e(TAG, "AuthenticationException", e);
        syncResult.stats.numAuthExceptions++;
        if (authtoken != null) {
            mAccountManager.invalidateAuthToken(account.type, authtoken);
        }
        try {
            authtoken = mAccountManager.blockingGetAuthToken(account, Constants.AUTHTOKEN_TYPE,
                    NOTIFY_AUTH_FAILURE);
        } catch (OperationCanceledException e1) {
            Log.e(TAG, "OperationCanceledExcetpion", e);
        } catch (AuthenticatorException e1) {
            Log.e(TAG, "AuthenticatorException", e);
            syncResult.stats.numParseExceptions++;
        } catch (IOException e1) {
            Log.e(TAG, "IOException", e);
            syncResult.stats.numIoExceptions++;
        }
    } catch (final ParseException e) {
        Log.e(TAG, "ParseException", e);
        syncResult.stats.numParseExceptions++;
        showNotificationError("Error parsing the information from facebook");
    } catch (final JSONException e) {
        Log.e(TAG, "JSONException", e);
        syncResult.stats.numParseExceptions++;
        showNotificationError("Error parsing the information from facebook");
    } catch (final Exception e) {
        Log.e(TAG, "Unknown exception", e);
    }
}

From source file:com.projecttango.experiments.basictango_button.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    // Lock the Tango configuration and reconnect to the service each time
    // the app/*w ww.j a  v a 2s .c o  m*/
    // is brought to the foreground.
    super.onResume();
    if (!mIsTangoServiceConnected) {
        startActivityForResult(Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING),
                Tango.TANGO_INTENT_ACTIVITYCODE);
    }

    // Clear all notification
    NotificationManager mNotifyMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotifyMgr.cancelAll();
}

From source file:pylapp.smoothclicker.android.notifiers.StatusBarNotifier.java

/**
 * Removes all notifications/*from  w  ww .  j  a va2s .  c o  m*/
 */
public void removeAllNotifications() {
    Logger.d(LOG_TAG, "Remove all notifications");
    NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancelAll();
}

From source file:za.co.neilson.alarm.alert.AlarmAlertActivity.java

@Override
protected void onDestroy() {
    try {/* w  ww .  j a  v a2s .  c o m*/
        if (vibrator != null)
            vibrator.cancel();
    } catch (Exception e) {

    }
    try {
        mediaPlayer.stop();
    } catch (Exception e) {

    }
    try {
        mediaPlayer.release();
    } catch (Exception e) {

    }
    NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancelAll();
    super.onDestroy();
}

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

/**
 * Update new message {@link Notification}.
 *
 * @param context {@link Context}//from ww w  . ja  v a  2 s  .  c o  m
 * @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:com.dsdar.thosearoundme.location.LocationUpdates.java

void initNotification(int cnt) {
    Log.d("TAG", "cnt...................=" + cnt);
    // prepare intent which is triggered if the
    // notification is selected

    NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nManager.cancelAll();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon)
            .setContentTitle("Those Around Me").setSound(soundUri).setAutoCancel(true)
            .setContentText("You received " + cnt + " Invitation");
    int NOTIFICATION_ID = 12345;

    Intent targetIntent = new Intent(this, SplashActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, targetIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    nManager.notify(NOTIFICATION_ID, builder.build());
}

From source file:com.kentli.cycletrack.RecordingService.java

private void clearNotifications() {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancelAll();

    if (timer != null) {
        timer.cancel();/*from w  w  w  . j  a  v a 2 s.  c om*/
        timer.purge();
    }
}