Example usage for android.support.v4.app NotificationManagerCompat from

List of usage examples for android.support.v4.app NotificationManagerCompat from

Introduction

In this page you can find the example usage for android.support.v4.app NotificationManagerCompat from.

Prototype

public static NotificationManagerCompat from(Context context) 

Source Link

Usage

From source file:com.irccloud.android.Notifications.java

public void deleteOldNotifications(int bid, long last_seen_eid) {
    boolean changed = false, pending = false;
    if (mNotificationTimerTask != null) {
        mNotificationTimerTask.cancel();
        pending = true;//w w w. j  a  va 2 s  .  com
    }

    ArrayList<Notification> notifications = getOtherNotifications();

    if (notifications.size() > 0) {
        for (Notification n : notifications) {
            if (n.bid == bid && n.eid <= last_seen_eid) {
                NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext())
                        .cancel((int) (n.eid / 1000));
                changed = true;
            }
        }
    }

    synchronized (mNotifications) {
        for (int i = 0; i < mNotifications.size(); i++) {
            Notification n = mNotifications.get(i);
            if (n.bid == bid && n.eid <= last_seen_eid) {
                mNotifications.remove(n);
                i--;
                NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext())
                        .cancel(bid);
                NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext())
                        .cancel((int) (n.eid / 1000));
                changed = true;
            }
        }
    }
    save();
    if (changed) {
        IRCCloudApplication.getInstance().getApplicationContext()
                .sendBroadcast(new Intent(DashClock.REFRESH_INTENT));
        try {
            if (PreferenceManager
                    .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext())
                    .getBoolean("notify_sony", false))
                NotificationUtil.deleteEvents(IRCCloudApplication.getInstance().getApplicationContext(),
                        com.sonyericsson.extras.liveware.aef.notification.Notification.EventColumns.FRIEND_KEY
                                + " = ?",
                        new String[] { String.valueOf(bid) });
        } catch (Exception e) {
        }
        updateTeslaUnreadCount();
    }

    if (pending)
        showNotifications(mTicker);
}

From source file:com.cnlms.wear.NotificationHelper.java

public static void raiseNotificationWithMultiRecipes(final Context context) {

    final int notificationId = 1;

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notif).setContentTitle("New Pancake Recipe!")
            .setContentText("Start making now!").setContentIntent(openRecipeIntent(context))
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.bg_pancakes1));

    final Notification secondPage = new NotificationCompat.Builder(context).setContentTitle("Step 1")
            .setContentText(RECIPE_STEP_1)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.bg_pancakes2))
            .build();//from   ww  w  .  j a v  a2s .  co m

    final Notification thirdPage = new NotificationCompat.Builder(context).setContentTitle("Step 2")
            .setContentText(RECIPE_STEP_2)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.bg_pancakes3))
            .build();

    builder.extend(new NotificationCompat.WearableExtender().addPage(secondPage).addPage(thirdPage)).build();

    NotificationManagerCompat.from(context).notify(notificationId, builder.build());

}

From source file:com.googlecode.mindbell.accessors.ContextAccessor.java

/**
 * This is about updating the ring notification when ringing the bell.
 *///  w w w . ja v  a2 s.  c o m
public void updateRingNotification(ActivityPrefsAccessor activityPrefs) {
    int visibility = (prefs.isNotificationVisibilityPublic()) ? NotificationCompat.VISIBILITY_PUBLIC
            : NotificationCompat.VISIBILITY_PRIVATE;
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
            context.getApplicationContext()) //
                    .setCategory(NotificationCompat.CATEGORY_ALARM) //
                    .setAutoCancel(true) // cancel notification on touch
                    .setColor(context.getResources().getColor(R.color.backgroundColor)) //
                    .setContentTitle(prefs.getNotificationTitle()) //
                    .setContentText(prefs.getNotificationText()).setSmallIcon(R.drawable.ic_stat_bell_ring) //
                    .setVisibility(visibility);
    if (activityPrefs.isVibrate()) {
        notificationBuilder.setVibrate(prefs.getVibrationPattern());
    }
    Notification notification = notificationBuilder.build();
    NotificationManagerCompat.from(context).notify(RING_NOTIFICATION_ID, notification);
}

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.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java

public void notifyUndefined(String title, String text) {
    Intent contentIntent = new Intent(this, MainActivity.class);
    //contentIntent.putExtra("navigation_page", MainActivity.PAGE_ANNOUNCEMENTS);
    contentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Intent settingsIntent = new Intent(this, MainActivity.class);
    settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS);
    settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, settingsIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle();
    notifStyle.bigText(text);/* ww  w  . jav a 2 s.  c  o  m*/
    notifStyle.setBigContentTitle(title);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon_nodpi).setContentTitle(title).setContentText(text)
            .setAutoCancel(true).setSound(defaultSoundUri)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent)
            .setStyle(notifStyle);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // Build the notification and issues it with notification manager.
    notificationManager.notify(NOTIFICATION_ID_UNDEFINED, notificationBuilder.build());
}

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

private void removeDisabledNotification() {
    NotificationManagerCompat.from(this).cancel(NOTIFY_DISABLED);
}

From source file:com.irccloud.android.data.collection.NotificationsList.java

public synchronized void excludeBid(int bid) {
    synchronized (dbLock) {
        excludeBid = -1;/*from   w  w  w  .j  a  v a 2s .c  o  m*/
        List<Notification> notifications = getOtherNotifications();

        if (notifications.size() > 0) {
            for (Notification n : notifications) {
                NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext())
                        .cancel((int) (n.eid / 1000));
            }
        }
        NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext()).cancel(bid);
        excludeBid = bid;
    }
}

From source file:com.bluros.music.MusicService.java

@Override
public void onCreate() {
    if (D)/*  w ww.  j a v a  2s . com*/
        Log.d(TAG, "Creating service");
    super.onCreate();

    mNotificationManager = NotificationManagerCompat.from(this);

    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);

    mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();

    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(),
            MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        setUpMediaSession();

    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();

    registerExternalStorageListener();

    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);

    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(SLEEP_MODE_STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    filter.addAction(RemoteSelectDialog.REMOTE_START_SCAN);
    filter.addAction(RemoteSelectDialog.REMOTE_STOP_SCAN);
    filter.addAction(RemoteSelectDialog.REMOTE_CONNECT);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);

    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true,
            mMediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true,
            mMediaStoreObserver);

    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);

    final Intent shutdownIntent = new Intent(this, MusicService.class);
    shutdownIntent.setAction(SHUTDOWN);

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);

    scheduleDelayedShutdown();

    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}

From source file:com.android.mail.utils.NotificationUtils.java

/**
 * Get all notifications for all accounts, optionally cancel them, and repost.
 * This happens when locale changes. If you only want to resend messages from one
 * account-folder pair, pass in the account and folder that should be resent.
 * All other account-folder pairs will not have their notifications resent.
 * All notifications will be resent if account or folder is null.
 *
 * @param context Current context.//w  w  w. java 2  s  . c o  m
 * @param cancelExisting True, if all notifications should be canceled before resending.
 *                       False, otherwise.
 * @param accountUri The {@link Uri} of the {@link Account} of the notification
 *                   upon which an action occurred, or {@code null}.
 * @param folderUri The {@link Uri} of the {@link Folder} of the notification
 *                  upon which an action occurred, or {@code null}.
 */
public static void resendNotifications(Context context, final boolean cancelExisting, final Uri accountUri,
        final FolderUri folderUri, final ContactFetcher contactFetcher) {
    LogUtils.i(LOG_TAG, "resendNotifications cancelExisting: %b, account: %s, folder: %s", cancelExisting,
            accountUri == null ? null : LogUtils.sanitizeName(LOG_TAG, accountUri.toString()),
            folderUri == null ? null : LogUtils.sanitizeName(LOG_TAG, folderUri.toString()));

    if (cancelExisting) {
        LogUtils.d(LOG_TAG, "resendNotifications - cancelling all");
        NotificationManagerCompat nm = NotificationManagerCompat.from(context);
        nm.cancelAll();
    }
    // Re-validate the notifications.
    final NotificationMap notificationMap = getNotificationMap(context);
    final Set<NotificationKey> keys = notificationMap.keySet();
    for (NotificationKey notification : keys) {
        final Folder folder = notification.folder;
        final int notificationId = getNotificationId(notification.account.getAccountManagerAccount(), folder);

        // Only resend notifications if the notifications are from the same folder
        // and same account as the undo notification that was previously displayed.
        if (accountUri != null && !Objects.equal(accountUri, notification.account.uri) && folderUri != null
                && !Objects.equal(folderUri, folder.folderUri)) {
            LogUtils.d(LOG_TAG,
                    "resendNotifications - not resending %s / %s" + " because it doesn't match %s / %s",
                    notification.account.uri, folder.folderUri, accountUri, folderUri);
            continue;
        }

        LogUtils.d(LOG_TAG, "resendNotifications - resending %s / %s", notification.account.uri,
                folder.folderUri);

        final NotificationAction undoableAction = NotificationActionUtils.sUndoNotifications
                .get(notificationId);
        if (undoableAction == null) {
            validateNotifications(context, folder, notification.account, true, false, notification,
                    contactFetcher);
        } else {
            // Create an undo notification
            NotificationActionUtils.createUndoNotification(context, undoableAction);
        }
    }
}

From source file:com.stasbar.knowyourself.alarms.AlarmNotifications.java

public static void clearNotification(Context context, AlarmInstance instance) {
    LogUtils.v("Clearing notifications for alarm instance: " + instance.mId);
    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.cancel(instance.hashCode());/*from ww  w . j a va2  s  .c om*/
    updateAlarmGroupNotification(context);
    updateAlarmGroupMissedNotification(context);
}