Example usage for android.app Notification PRIORITY_HIGH

List of usage examples for android.app Notification PRIORITY_HIGH

Introduction

In this page you can find the example usage for android.app Notification PRIORITY_HIGH.

Prototype

int PRIORITY_HIGH

To view the source code for android.app Notification PRIORITY_HIGH.

Click Source Link

Document

Higher #priority , for more important notifications or alerts.

Usage

From source file:com.peptrack.gps.locationupdatesforegroundservice.LocationUpdatesService.java

/**
 * Returns the {@link NotificationCompat} used as part of the foreground service.
 *//*from   ww w .j a v  a  2s  . c o  m*/
private Notification getNotification() {
    Intent intent = new Intent(this, LocationUpdatesService.class);

    CharSequence text = Utils.getLocationText(mLocation);

    // Extra to help us figure out if we arrived in onStartCommand via the notification or not.
    intent.putExtra(EXTRA_STARTED_FROM_NOTIFICATION, true);

    // The PendingIntent that leads to a call to onStartCommand() in this service.
    PendingIntent servicePendingIntent = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // The PendingIntent to launch activity.
    PendingIntent activityPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MainActivity.class), 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .addAction(R.drawable.ic_launch, getString(R.string.launch_activity), activityPendingIntent)
            .addAction(R.drawable.ic_cancel, getString(R.string.remove_location_updates), servicePendingIntent)
            .setContentText(text).setContentTitle(Utils.getLocationTitle(this)).setOngoing(true)
            .setPriority(Notification.PRIORITY_HIGH).setSmallIcon(R.mipmap.ic_launcher).setTicker(text)
            .setWhen(System.currentTimeMillis());

    // Set the Channel ID for Android O.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        builder.setChannelId(CHANNEL_ID); // Channel ID
    }

    return builder.build();
}

From source file:com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity.java

private void generateBigTextStyleNotification() {

    Log.d(TAG, "generateBigTextStyleNotification()");

    // Main steps for building a BIG_TEXT_STYLE notification:
    //      0. Get your data
    //      1. Build the BIG_TEXT_STYLE
    //      2. Set up main Intent for notification
    //      3. Create additional Actions for the Notification
    //      4. Build and issue the notification

    // 0. Get your data (everything unique per Notification)
    MockDatabase.BigTextStyleReminderAppData bigTextStyleReminderAppData = MockDatabase.getBigTextStyleData();

    // 1. Build the BIG_TEXT_STYLE
    BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle()
            // Overrides ContentText in the big form of the template
            .bigText(bigTextStyleReminderAppData.getBigText())
            // Overrides ContentTitle in the big form of the template
            .setBigContentTitle(bigTextStyleReminderAppData.getBigContentTitle())
            // Summary line after the detail section in the big form of the template
            // Note: To improve readability, don't overload the user with info. If Summary Text
            // doesn't add critical information, you should skip it.
            .setSummaryText(bigTextStyleReminderAppData.getSummaryText());

    // 2. Set up main Intent for notification
    Intent mainIntent = new Intent(this, BigTextMainActivity.class);

    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // 3. Create additional Actions (Intents) for the Notification

    // In our case, we create two additional actions: a Snooze action and a Dismiss action.

    // Snooze Action
    Intent snoozeIntent = new Intent(this, BigTextIntentService.class);
    snoozeIntent.setAction(BigTextIntentService.ACTION_SNOOZE);

    PendingIntent snoozePendingIntent = PendingIntent.getService(this, 0, snoozeIntent, 0);
    NotificationCompat.Action snoozeAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_alarm_white_48dp, "Snooze", snoozePendingIntent).build();

    // Dismiss Action
    Intent dismissIntent = new Intent(this, BigTextIntentService.class);
    dismissIntent.setAction(BigTextIntentService.ACTION_DISMISS);

    PendingIntent dismissPendingIntent = PendingIntent.getService(this, 0, dismissIntent, 0);
    NotificationCompat.Action dismissAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_cancel_white_48dp, "Dismiss", dismissPendingIntent).build();

    // 4. Build and issue the notification

    // Because we want this to be a new notification (not updating a previous notification), we
    // create a new Builder. Later, we use the same global builder to get back the notification
    // we built here for the snooze action, that is, canceling the notification and relaunching
    // it several seconds later.

    NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(
            getApplicationContext());/* w  w w  .ja v  a  2 s.com*/

    GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);

    notificationCompatBuilder
            // BIG_TEXT_STYLE sets title and content
            .setStyle(bigTextStyle).setContentTitle(bigTextStyleReminderAppData.getContentTitle())
            .setContentText(bigTextStyleReminderAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_alarm_white_48dp))
            // Set primary color (important for Wear 2.0 Notifications)
            .setColor(getResources().getColor(R.color.colorPrimary))

            .setCategory(Notification.CATEGORY_REMINDER).setPriority(Notification.PRIORITY_HIGH)

            // Shows content on the lock-screen
            .setVisibility(Notification.VISIBILITY_PUBLIC)

            // Adds additional actions specified above
            .addAction(snoozeAction).addAction(dismissAction);

    /* REPLICATE_NOTIFICATION_STYLE_CODE:
     * You can replicate Notification Style functionality on Wear 2.0 (24+) by not setting the
     * main content intent, that is, skipping the call setContentIntent(). However, you need to
     * still allow the user to open the native Wear app from the Notification itself, so you
     * add an action to launch the app.
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

        // Enables launching app in Wear 2.0 while keeping the old Notification Style behavior.
        NotificationCompat.Action mainAction = new NotificationCompat.Action.Builder(R.drawable.ic_launcher,
                "Open", mainPendingIntent).build();

        notificationCompatBuilder.addAction(mainAction);

    } else {
        // Wear 1.+ still functions the same, so we set the main content intent.
        notificationCompatBuilder.setContentIntent(mainPendingIntent);
    }

    Notification notification = notificationCompatBuilder.build();

    mNotificationManagerCompat.notify(NOTIFICATION_ID, notification);

    // Close app to demonstrate notification in steam.
    finish();
}

From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static Notification makePinNotification(Context context, Builder builder, ContentSet task,
        boolean withSound, boolean withTickerText, boolean withHeadsUpNotification) {
    Resources resources = context.getResources();

    // reset actions
    builder.mActions = new ArrayList<Action>(2);

    // content/*from www.j  av a2s. co  m*/
    builder.setSmallIcon(R.drawable.ic_pin_white_24dp).setContentTitle(TaskFieldAdapters.TITLE.get(task))
            .setOngoing(true).setShowWhen(false);

    // set priority for HeadsUpNotification
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
        if (withHeadsUpNotification) {
            builder.setPriority(Notification.PRIORITY_HIGH);
        } else {
            builder.setPriority(Notification.PRIORITY_DEFAULT);
        }
    }

    // color is based on the priority of the task. If the task has no priority we use the primary color.
    Integer priority = TaskFieldAdapters.PRIORITY.get(task);
    if (priority != null && priority > 0) {
        if (priority < 5) {
            builder.setColor(resources.getColor(R.color.priority_red));
        }
        if (priority == 5) {
            builder.setColor(resources.getColor(R.color.priority_yellow));
        }
        if (priority > 5 && priority <= 9) {
            builder.setColor(resources.getColor(R.color.priority_green));
        }
    } else {
        builder.setColor(resources.getColor(R.color.colorPrimary));
    }

    // description
    String contentText = makePinNotificationContentText(context, task);
    if (contentText != null) {
        builder.setContentText(contentText);
    }

    // ticker text
    if (withTickerText) {
        builder.setTicker(
                context.getString(R.string.notification_task_pin_ticker, (TaskFieldAdapters.TITLE.get(task))));
    }

    // click action
    Intent resultIntent = new Intent(Intent.ACTION_VIEW);
    resultIntent.setData(task.getUri());
    resultIntent.setPackage(context.getPackageName());

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    // complete action
    Boolean closed = TaskFieldAdapters.IS_CLOSED.get(task);
    if (closed == null || !closed) {
        Time dueTime = TaskFieldAdapters.DUE.get(task);
        long dueTimestamp = dueTime == null ? 0 : dueTime.toMillis(true);

        NotificationAction completeAction = new NotificationAction(NotificationUpdaterService.ACTION_COMPLETE,
                R.string.notification_action_completed, TaskFieldAdapters.TASK_ID.get(task), task.getUri(),
                dueTimestamp);
        builder.addAction(NotificationUpdaterService.getCompleteAction(context,
                NotificationActionUtils.getNotificationActionPendingIntent(context, completeAction)));
    }

    // unpin action
    builder.addAction(NotificationUpdaterService.getUnpinAction(context, TaskFieldAdapters.TASK_ID.get(task),
            task.getUri()));

    // sound
    if (withSound) {
        builder.setDefaults(Notification.DEFAULT_ALL);
    } else {
        builder.setDefaults(Notification.DEFAULT_LIGHTS);
    }

    return builder.build();
}

From source file:net.networksaremadeofstring.rhybudd.Notifications.java

public static void SendPollNotification(int EventCount, List<String> EventDetails, Context context) {
    Intent notificationIntent = new Intent(context, ViewZenossEventsListActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("forceRefresh", true);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Intent broadcastMassAck = new Intent();
    broadcastMassAck.setAction(MassAcknowledgeReceiver.BROADCAST_ACTION);
    PendingIntent pBroadcastMassAck = PendingIntent.getBroadcast(context, 0, broadcastMassAck, 0);

    /*Intent broadcastIgnore = new Intent();
    broadcastIgnore.setAction(BatchIgnoreReceiver.BROADCAST_ACTION);
    PendingIntent pBroadcastIgnore = PendingIntent.getBroadcast(this,0,broadcastIgnore,0);*/

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    Uri soundURI;//from w w w  .j a va2 s .  c  om
    int Flags = -1;
    String Event1 = "--", Event2 = "---";
    int remainingCount = 0;

    try {
        if (settings.getBoolean("notificationSound", true)) {
            if (settings.getString("notificationSoundChoice", "").equals("")) {
                soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            } else {
                try {
                    soundURI = Uri.parse(settings.getString("notificationSoundChoice", ""));
                } catch (Exception e) {
                    soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                }
            }
        } else {
            soundURI = null;
        }
    } catch (Exception e) {
        soundURI = null;
    }

    try {
        if (EventDetails.size() > 1) {
            Event1 = EventDetails.get(0);
            Event2 = EventDetails.get(1);
            remainingCount = EventCount - 2;
        } else {
            Event1 = EventDetails.get(0);
            remainingCount = EventCount - 1;
        }
    } catch (Exception e) {

    }

    long[] vibrate = { 0, 100, 200, 300 };

    try {
        AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

        //Log.e("audio.getRingerMode()",Integer.toString(audio.getRingerMode()));
        switch (audio.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            //Do nothing to fix GitHub issue #13
            //Log.e("AudioManager","Doing nothing because we are silent");
            vibrate = new long[] { 0, 0 };
            break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_stat_alert)
                .setContentTitle(Integer.toString(EventCount) + " new Zenoss Events!")
                .setContentText("Tap to start Rhybudd").setContentIntent(contentIntent).setNumber(EventCount)
                .setSound(soundURI).setVibrate(vibrate).setAutoCancel(true).setOngoing(false)
                .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck)
                .setPriority(Notification.PRIORITY_HIGH);

        Notification notif = mBuilder.build();
        notif.tickerText = Integer.toString(EventCount) + " new Zenoss Events!";

        if (settings.getBoolean("notificationSoundInsistent", false))
            notif.flags |= Notification.FLAG_INSISTENT;

        NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNM.notify(NOTIFICATION_POLLED_ALERTS, notif);
    } catch (Exception e) {

    }
}

From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java

private void showCollapsedNotificationWithNext(final Context context, String title, String text,
        Long nextBroadcastTime) {
    Intent activityIntent = new Intent(context, DeskClock.class);
    activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    activityIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.TIMER_TAB_INDEX);
    PendingIntent pendingActivityIntent = PendingIntent.getActivity(context, 0, activityIntent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
    showCollapsedNotification(context, title, text, Notification.PRIORITY_HIGH, pendingActivityIntent,
            IN_USE_NOTIFICATION_ID, false);

    if (nextBroadcastTime == null) {
        return;//from  ww w.j a v  a2s . co  m
    }
    Intent nextBroadcast = new Intent();
    nextBroadcast.setAction(Timers.NOTIF_IN_USE_SHOW);
    PendingIntent pendingNextBroadcast = PendingIntent.getBroadcast(context, 0, nextBroadcast, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (Utils.isKitKatOrLater()) {
        alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast);
    } else {
        alarmManager.set(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast);
    }
}

From source file:com.example.android.wearable.wear.wearnotifications.MainActivity.java

private void generateBigTextStyleNotification() {

    Log.d(TAG, "generateBigTextStyleNotification()");

    // Main steps for building a BIG_TEXT_STYLE notification:
    //      0. Get your data
    //      1. Build the BIG_TEXT_STYLE
    //      2. Set up main Intent for notification
    //      3. Create additional Actions for the Notification
    //      4. Build and issue the notification

    // 0. Get your data (everything unique per Notification)
    MockDatabase.BigTextStyleReminderAppData bigTextStyleReminderAppData = MockDatabase.getBigTextStyleData();

    // 1. Build the BIG_TEXT_STYLE
    BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle()
            // Overrides ContentText in the big form of the template
            .bigText(bigTextStyleReminderAppData.getBigText())
            // Overrides ContentTitle in the big form of the template
            .setBigContentTitle(bigTextStyleReminderAppData.getBigContentTitle())
            // Summary line after the detail section in the big form of the template
            // Note: To improve readability, don't overload the user with info. If Summary Text
            // doesn't add critical information, you should skip it.
            .setSummaryText(bigTextStyleReminderAppData.getSummaryText());

    // 2. Set up main Intent for notification
    Intent notifyIntent = new Intent(this, BigTextMainActivity.class);

    // When creating your Intent, you need to take into account the back state, i.e., what
    // happens after your Activity launches and the user presses the back button.

    // There are two options:
    //      1. Regular activity - You're starting an Activity that's part of the application's
    //      normal workflow.

    //      2. Special activity - The user only sees this Activity if it's started from a
    //      notification. In a sense, the Activity extends the notification by providing
    //      information that would be hard to display in the notification itself.

    // For the BIG_TEXT_STYLE notification, we will consider the activity launched by the main
    // Intent as a special activity, so we will follow option 2.

    // For an example of option 1, check either the MESSAGING_STYLE or BIG_PICTURE_STYLE
    // examples.//from ww w .j  av a 2  s .  com

    // For more information, check out our dev article:
    // https://developer.android.com/training/notify-user/navigation.html

    // Sets the Activity to start in a new, empty task
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // 3. Create additional Actions (Intents) for the Notification

    // In our case, we create two additional actions: a Snooze action and a Dismiss action
    // Snooze Action
    Intent snoozeIntent = new Intent(this, BigTextIntentService.class);
    snoozeIntent.setAction(BigTextIntentService.ACTION_SNOOZE);

    PendingIntent snoozePendingIntent = PendingIntent.getService(this, 0, snoozeIntent, 0);
    NotificationCompat.Action snoozeAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_alarm_white_48dp, "Snooze", snoozePendingIntent).build();

    // Dismiss Action
    Intent dismissIntent = new Intent(this, BigTextIntentService.class);
    dismissIntent.setAction(BigTextIntentService.ACTION_DISMISS);

    PendingIntent dismissPendingIntent = PendingIntent.getService(this, 0, dismissIntent, 0);
    NotificationCompat.Action dismissAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_cancel_white_48dp, "Dismiss", dismissPendingIntent).build();

    // 4. Build and issue the notification

    // Because we want this to be a new notification (not updating a previous notification), we
    // create a new Builder. Later, we use the same global builder to get back the notification
    // we built here for the snooze action, that is, canceling the notification and relaunching
    // it several seconds later.

    NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(
            getApplicationContext());

    GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);

    Notification notification = notificationCompatBuilder
            // BIG_TEXT_STYLE sets title and content for API 16 (4.1 and after)
            .setStyle(bigTextStyle)
            // Title for API <16 (4.0 and below) devices
            .setContentTitle(bigTextStyleReminderAppData.getContentTitle())
            // Content for API <24 (7.0 and below) devices
            .setContentText(bigTextStyleReminderAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_alarm_white_48dp))
            .setContentIntent(notifyPendingIntent)
            // Set primary color (important for Wear 2.0 Notifications)
            .setColor(getResources().getColor(R.color.colorPrimary))

            // SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+)
            // devices and all Android Wear devices. If you have more than one notification and
            // you prefer a different summary notification, set a group key and create a
            // summary notification via
            // .setGroupSummary(true)
            // .setGroup(GROUP_KEY_YOUR_NAME_HERE)

            .setCategory(Notification.CATEGORY_REMINDER).setPriority(Notification.PRIORITY_HIGH)

            // Shows content on the lock-screen
            .setVisibility(Notification.VISIBILITY_PUBLIC)

            // Adds additional actions specified above
            .addAction(snoozeAction).addAction(dismissAction)

            .build();

    mNotificationManagerCompat.notify(NOTIFICATION_ID, notification);
}

From source file:com.lambdasoup.quickfit.alarm.AlarmService.java

@WorkerThread
private void refreshNotificationDisplay() {
    try (Cursor toNotify = getContentResolver().query(QuickFitContentProvider.getUriWorkoutsList(),
            new String[] { WorkoutEntry.SCHEDULE_ID, WorkoutEntry.WORKOUT_ID, WorkoutEntry.ACTIVITY_TYPE,
                    WorkoutEntry.LABEL, WorkoutEntry.DURATION_MINUTES },
            ScheduleEntry.TABLE_NAME + "." + ScheduleEntry.COL_SHOW_NOTIFICATION + "=?",
            new String[] { Integer.toString(ScheduleEntry.SHOW_NOTIFICATION_YES) }, null)) {
        int count = toNotify == null ? 0 : toNotify.getCount();
        if (count == 0) {
            Timber.d("refreshNotificationDisplay: no events");
            NotificationManager notificationManager = (NotificationManager) getSystemService(
                    NOTIFICATION_SERVICE);
            notificationManager.cancel(Constants.NOTIFICATION_ALARM);
            return;
        }//ww w .j ava  2  s. c o  m

        long[] scheduleIds = new long[count];
        int i = 0;
        toNotify.moveToPosition(-1);
        while (toNotify.moveToNext()) {
            scheduleIds[i] = toNotify.getLong(toNotify.getColumnIndex(WorkoutEntry.SCHEDULE_ID));
            i++;
        }

        PendingIntent cancelIntent = PendingIntent.getService(getApplicationContext(), 0,
                getIntentOnNotificationsCanceled(this, scheduleIds), PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder notification;
        if (count == 1) {
            Timber.d("refreshNotificationDisplay: single event");
            toNotify.moveToFirst();
            notification = notifySingleEvent(toNotify, cancelIntent);
        } else {
            Timber.d("refreshNotificationDisplay: multiple events");
            toNotify.moveToPosition(-1);
            notification = notifyMultipleEvents(toNotify, cancelIntent);
        }

        notification.setDeleteIntent(cancelIntent);
        notification.setAutoCancel(true);
        notification.setPriority(Notification.PRIORITY_HIGH);
        notification.setSmallIcon(R.drawable.ic_stat_quickfit_icon);
        notification.setColor(ContextCompat.getColor(this, R.color.colorPrimary));

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        String ringtoneUriStr = preferences.getString(getString(R.string.pref_key_notification_ringtone), null);
        if (ringtoneUriStr == null) {
            notification.setSound(
                    RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION));
        } else if (!ringtoneUriStr.isEmpty()) {
            notification.setSound(Uri.parse(ringtoneUriStr));
        }
        boolean ledOn = preferences.getBoolean(getString(R.string.pref_key_notification_led), true);
        boolean vibrationOn = preferences.getBoolean(getString(R.string.pref_key_notification_vibrate), true);
        notification.setDefaults(
                (ledOn ? Notification.DEFAULT_LIGHTS : 0) | (vibrationOn ? Notification.DEFAULT_VIBRATE : 0));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            notification.setCategory(Notification.CATEGORY_ALARM);
        }

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(Constants.NOTIFICATION_ALARM, notification.build());
    }
}

From source file:com.example.android.alertbuddy.BluetoothLeService.java

/**
 * This function will be used to update the notification as required. Note that this
 * function must be called explicitly by the class that does the detection.
 * The parameter value used to be the value (1, 2, 3, 4) that's be passed back by
 * the board. Depending on how we want to integrate the Detection algorithm with this,
 * this can be changed accordingly./*  w ww. j av  a  2 s  .com*/
 * @param value
 */
protected void updateNotification(String value) {

    // set up icon if we want later
    mBuilder.setSmallIcon(R.drawable.ic_launcher);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, mIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pendingIntent);

    // Set up builder
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    mBuilder.setContentTitle("Environment Alert!");

    mBuilder.setContentText(value);

    // This part is for heads-up notification
    mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    mBuilder.setPriority(Notification.PRIORITY_HIGH);
    lockScreenNotification();

    // Put the finished builder to notificationManager
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.androidinspain.deskclock.data.TimerNotificationBuilder.java

Notification buildMissed(Context context, NotificationModel nm, List<Timer> missedTimers) {
    final Timer timer = missedTimers.get(0);
    final int count = missedTimers.size();

    // Compute some values required below.
    final long base = getChronometerBase(timer);
    final String pname = context.getPackageName();
    final Resources res = context.getResources();

    final Action action;

    final CharSequence stateText;
    if (count == 1) {
        // Single timer is missed.
        if (TextUtils.isEmpty(timer.getLabel())) {
            stateText = res.getString(com.androidinspain.deskclock.R.string.missed_timer_notification_label);
        } else {/* w ww  .  ja v  a  2  s  .  co m*/
            stateText = res.getString(
                    com.androidinspain.deskclock.R.string.missed_named_timer_notification_label,
                    timer.getLabel());
        }

        // Reset button
        final Intent reset = new Intent(context, TimerService.class).setAction(TimerService.ACTION_RESET_TIMER)
                .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId());

        @DrawableRes
        final int icon1 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp;
        final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_reset);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);
        action = new Action.Builder(icon1, title1, intent1).build();
    } else {
        // Multiple missed timers.
        stateText = res.getString(com.androidinspain.deskclock.R.string.timer_multi_missed, count);

        final Intent reset = TimerService.createResetMissedTimersIntent(context);

        @DrawableRes
        final int icon1 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp;
        final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_reset_all);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);
        action = new Action.Builder(icon1, title1, intent1).build();
    }

    // Intent to load the app and show the timer when the notification is tapped.
    final Intent showApp = new Intent(context, TimerService.class).setAction(TimerService.ACTION_SHOW_TIMER)
            .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId())
            .putExtra(Events.EXTRA_EVENT_LABEL, com.androidinspain.deskclock.R.string.label_notification);

    final PendingIntent pendingShowApp = PendingIntent.getService(context, REQUEST_CODE_MISSING, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    final Builder notification = new NotificationCompat.Builder(context).setLocalOnly(true).setShowWhen(false)
            .setAutoCancel(false).setContentIntent(pendingShowApp).setPriority(Notification.PRIORITY_HIGH)
            .setCategory(NotificationCompat.CATEGORY_ALARM)
            .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_timer)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setSortKey(nm.getTimerNotificationMissedSortKey())
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle()).addAction(action)
            .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background));

    if (Utils.isNOrLater()) {
        notification.setCustomContentView(buildChronometer(pname, base, true, stateText))
                .setGroup(nm.getTimerNotificationGroupKey());
    } else {
        final CharSequence contentText = AlarmUtils.getFormattedTime(context,
                timer.getWallClockExpirationTime());
        notification.setContentText(contentText).setContentTitle(stateText);
    }

    return notification.build();
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java

private int getPriorityOfMessage(MFPInternalPushMessage message) {
    String priorityFromServer = message.getPriority();
    MFPPushNotificationOptions options = MFPPush.getInstance().getNotificationOptions();
    int priorityPreSetValue = 0;

    if (options != null && options.getPriority() != null) {
        priorityPreSetValue = options.getPriority().getValue();
    }//from  ww w  . j  ava 2  s . c om

    if (priorityFromServer != null) {
        if (priorityFromServer.equalsIgnoreCase(MFPPushConstants.PRIORITY_MAX)) {
            return Notification.PRIORITY_MAX;
        } else if (priorityFromServer.equalsIgnoreCase(MFPPushConstants.PRIORITY_MIN)) {
            return Notification.PRIORITY_MIN;
        } else if (priorityFromServer.equalsIgnoreCase(MFPPushConstants.PRIORITY_HIGH)) {
            return Notification.PRIORITY_HIGH;
        } else if (priorityFromServer.equalsIgnoreCase(MFPPushConstants.PRIORITY_LOW)) {
            return Notification.PRIORITY_LOW;
        }
    } else if (priorityPreSetValue != 0) {
        return priorityPreSetValue;
    }
    return Notification.PRIORITY_DEFAULT;
}