Example usage for android.app Notification PRIORITY_MAX

List of usage examples for android.app Notification PRIORITY_MAX

Introduction

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

Prototype

int PRIORITY_MAX

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

Click Source Link

Document

Highest #priority , for your application's most important items that require the user's prompt attention or input.

Usage

From source file:it.mb.whatshare.SendToGCMActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private Notification buildForJellyBean(NotificationCompat.Builder builder) {
    builder.setPriority(Notification.PRIORITY_MAX);
    return builder.build();
}

From source file:com.android.deskclock.data.StopwatchModel.java

/**
 * Updates the notification to reflect the latest state of the stopwatch and recorded laps.
 *//*from   w  ww.  j a  v  a  2  s.com*/
void updateNotification() {
    final Stopwatch stopwatch = getStopwatch();

    // Notification should be hidden if the stopwatch has no time or the app is open.
    if (stopwatch.isReset() || mNotificationModel.isApplicationInForeground()) {
        mNotificationManager.cancel(mNotificationModel.getStopwatchNotificationId());
        return;
    }

    @StringRes
    final int eventLabel = R.string.label_notification;

    // Intent to load the app when the notification is tapped.
    final Intent showApp = new Intent(mContext, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final PendingIntent pendingShowApp = PendingIntent.getActivity(mContext, 0, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    // Compute some values required below.
    final boolean running = stopwatch.isRunning();
    final String pname = mContext.getPackageName();
    final Resources res = mContext.getResources();
    final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime();

    final RemoteViews collapsed = new RemoteViews(pname, R.layout.stopwatch_notif_collapsed);
    collapsed.setChronometer(R.id.swn_collapsed_chronometer, base, null, running);
    collapsed.setOnClickPendingIntent(R.id.swn_collapsed_hitspace, pendingShowApp);
    collapsed.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch);

    final RemoteViews expanded = new RemoteViews(pname, R.layout.stopwatch_notif_expanded);
    expanded.setChronometer(R.id.swn_expanded_chronometer, base, null, running);
    expanded.setOnClickPendingIntent(R.id.swn_expanded_hitspace, pendingShowApp);
    expanded.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch);

    @IdRes
    final int leftButtonId = R.id.swn_left_button;
    @IdRes
    final int rightButtonId = R.id.swn_right_button;
    if (running) {
        // Left button: Pause
        expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_pause_button));
        setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_pause_24dp);
        final Intent pause = new Intent(mContext, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        expanded.setOnClickPendingIntent(leftButtonId, pendingServiceIntent(pause));

        // Right button: Add Lap
        if (canAddMoreLaps()) {
            expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_lap_button));
            setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_sw_lap_24dp);

            final Intent lap = new Intent(mContext, StopwatchService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
            expanded.setOnClickPendingIntent(rightButtonId, pendingServiceIntent(lap));
            expanded.setViewVisibility(rightButtonId, VISIBLE);
        } else {
            expanded.setViewVisibility(rightButtonId, INVISIBLE);
        }

        // Show the current lap number if any laps have been recorded.
        final int lapCount = getLaps().size();
        if (lapCount > 0) {
            final int lapNumber = lapCount + 1;
            final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber);
            collapsed.setTextViewText(R.id.swn_collapsed_laps, lap);
            collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE);
            expanded.setTextViewText(R.id.swn_expanded_laps, lap);
            expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE);
        } else {
            collapsed.setViewVisibility(R.id.swn_collapsed_laps, GONE);
            expanded.setViewVisibility(R.id.swn_expanded_laps, GONE);
        }
    } else {
        // Left button: Start
        expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_start_button));
        setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_start_24dp);
        final Intent start = new Intent(mContext, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        expanded.setOnClickPendingIntent(leftButtonId, pendingServiceIntent(start));

        // Right button: Reset (HandleDeskClockApiCalls will also bring forward the app)
        expanded.setViewVisibility(rightButtonId, VISIBLE);
        expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_reset_button));
        setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_reset_24dp);
        final Intent reset = new Intent(mContext, HandleDeskClockApiCalls.class)
                .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        expanded.setOnClickPendingIntent(rightButtonId, pendingActivityIntent(reset));

        // Indicate the stopwatch is paused.
        collapsed.setTextViewText(R.id.swn_collapsed_laps, res.getString(R.string.swn_paused));
        collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE);
        expanded.setTextViewText(R.id.swn_expanded_laps, res.getString(R.string.swn_paused));
        expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE);
    }

    // Swipe away will reset the stopwatch without bringing forward the app.
    final Intent reset = new Intent(mContext, StopwatchService.class)
            .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final Notification notification = new NotificationCompat.Builder(mContext).setLocalOnly(true)
            .setOngoing(running).setContent(collapsed).setAutoCancel(stopwatch.isPaused())
            .setPriority(Notification.PRIORITY_MAX).setDeleteIntent(pendingServiceIntent(reset))
            .setSmallIcon(R.drawable.ic_tab_stopwatch_activated).build();
    notification.bigContentView = expanded;
    mNotificationManager.notify(mNotificationModel.getStopwatchNotificationId(), notification);
}

From source file:com.onyx.deskclock.deskclock.data.StopwatchModel.java

/**
 * Updates the notification to reflect the latest state of the stopwatch and recorded laps.
 *//*www .j a  v  a  2s  .c o m*/
void updateNotification() {
    final Stopwatch stopwatch = getStopwatch();

    // Notification should be hidden if the stopwatch has no time or the app is open.
    if (stopwatch.isReset() || mNotificationModel.isApplicationInForeground()) {
        mNotificationManager.cancel(mNotificationModel.getStopwatchNotificationId());
        return;
    }

    @StringRes
    final int eventLabel = R.string.label_notification;

    // Intent to load the app when the notification is tapped.
    final Intent showApp = new Intent(mContext, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final PendingIntent pendingShowApp = PendingIntent.getActivity(mContext, 0, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    // Compute some values required below.
    final boolean running = stopwatch.isRunning();
    final String pname = mContext.getPackageName();
    final Resources res = mContext.getResources();
    final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime();

    final RemoteViews collapsed = new RemoteViews(pname, R.layout.stopwatch_notif_collapsed);
    collapsed.setChronometer(R.id.swn_collapsed_chronometer, base, null, running);
    collapsed.setOnClickPendingIntent(R.id.swn_collapsed_hitspace, pendingShowApp);
    collapsed.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch);

    final RemoteViews expanded = new RemoteViews(pname, R.layout.stopwatch_notif_expanded);
    expanded.setChronometer(R.id.swn_expanded_chronometer, base, null, running);
    expanded.setOnClickPendingIntent(R.id.swn_expanded_hitspace, pendingShowApp);
    expanded.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch);

    @IdRes
    final int leftButtonId = R.id.swn_left_button;
    @IdRes
    final int rightButtonId = R.id.swn_right_button;
    if (running) {
        // Left button: Pause
        expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_pause_button));
        //            setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_pause_24dp);
        final Intent pause = new Intent(mContext, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        expanded.setOnClickPendingIntent(leftButtonId, pendingServiceIntent(pause));

        // Right button: Add Lap
        if (canAddMoreLaps()) {
            expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_lap_button));
            //                setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_sw_lap_24dp);

            final Intent lap = new Intent(mContext, StopwatchService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
            expanded.setOnClickPendingIntent(rightButtonId, pendingServiceIntent(lap));
            expanded.setViewVisibility(rightButtonId, VISIBLE);
        } else {
            expanded.setViewVisibility(rightButtonId, INVISIBLE);
        }

        // Show the current lap number if any laps have been recorded.
        final int lapCount = getLaps().size();
        if (lapCount > 0) {
            final int lapNumber = lapCount + 1;
            final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber);
            collapsed.setTextViewText(R.id.swn_collapsed_laps, lap);
            collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE);
            expanded.setTextViewText(R.id.swn_expanded_laps, lap);
            expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE);
        } else {
            collapsed.setViewVisibility(R.id.swn_collapsed_laps, GONE);
            expanded.setViewVisibility(R.id.swn_expanded_laps, GONE);
        }
    } else {
        // Left button: Start
        expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_start_button));
        //            setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_start_24dp);
        final Intent start = new Intent(mContext, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        expanded.setOnClickPendingIntent(leftButtonId, pendingServiceIntent(start));

        // Right button: Reset (HandleDeskClockApiCalls will also bring forward the app)
        expanded.setViewVisibility(rightButtonId, VISIBLE);
        expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_reset_button));
        //            setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_reset_24dp);
        final Intent reset = new Intent(mContext, HandleDeskClockApiCalls.class)
                .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        expanded.setOnClickPendingIntent(rightButtonId, pendingActivityIntent(reset));

        // Indicate the stopwatch is paused.
        collapsed.setTextViewText(R.id.swn_collapsed_laps, res.getString(R.string.swn_paused));
        collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE);
        expanded.setTextViewText(R.id.swn_expanded_laps, res.getString(R.string.swn_paused));
        expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE);
    }

    // Swipe away will reset the stopwatch without bringing forward the app.
    final Intent reset = new Intent(mContext, StopwatchService.class)
            .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final Notification notification = new NotificationCompat.Builder(mContext).setLocalOnly(true)
            .setOngoing(running).setContent(collapsed).setAutoCancel(stopwatch.isPaused())
            .setPriority(Notification.PRIORITY_MAX).setDeleteIntent(pendingServiceIntent(reset))
            .setSmallIcon(R.drawable.ic_tab_stopwatch_activated).build();
    if (Build.VERSION.SDK_INT >= 16) {
        notification.bigContentView = expanded;
    }
    mNotificationManager.notify(mNotificationModel.getStopwatchNotificationId(), notification);
}

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

Notification buildHeadsUp(Context context, List<Timer> expired) {
    final Timer timer = expired.get(0);

    // First action intent is to reset all timers.
    @DrawableRes// ww w  . j av a2 s.  c  o m
    final int icon1 = com.androidinspain.deskclock.R.drawable.ic_stop_24dp;
    final Intent reset = TimerService.createResetExpiredTimersIntent(context);
    final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);

    // Generate some descriptive text, a title, and an action name based on the timer count.
    final CharSequence stateText;
    final int count = expired.size();
    final List<Action> actions = new ArrayList<>(2);
    if (count == 1) {
        final String label = timer.getLabel();
        if (TextUtils.isEmpty(label)) {
            stateText = context.getString(com.androidinspain.deskclock.R.string.timer_times_up);
        } else {
            stateText = label;
        }

        // Left button: Reset single timer
        final CharSequence title1 = context.getString(com.androidinspain.deskclock.R.string.timer_stop);
        actions.add(new Action.Builder(icon1, title1, intent1).build());

        // Right button: Add minute
        final Intent addTime = TimerService.createAddMinuteTimerIntent(context, timer.getId());
        final PendingIntent intent2 = Utils.pendingServiceIntent(context, addTime);
        @DrawableRes
        final int icon2 = com.androidinspain.deskclock.R.drawable.ic_add_24dp;
        final CharSequence title2 = context.getString(com.androidinspain.deskclock.R.string.timer_plus_1_min);
        actions.add(new Action.Builder(icon2, title2, intent2).build());
    } else {
        stateText = context.getString(com.androidinspain.deskclock.R.string.timer_multi_times_up, count);

        // Left button: Reset all timers
        final CharSequence title1 = context.getString(com.androidinspain.deskclock.R.string.timer_stop_all);
        actions.add(new Action.Builder(icon1, title1, intent1).build());
    }

    final long base = getChronometerBase(timer);

    final String pname = context.getPackageName();

    // Content intent shows the timer full screen when clicked.
    final Intent content = new Intent(context, ExpiredTimersActivity.class);
    final PendingIntent contentIntent = Utils.pendingActivityIntent(context, content);

    // Full screen intent has flags so it is different than the content intent.
    final Intent fullScreen = new Intent(context, ExpiredTimersActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    final PendingIntent pendingFullScreen = Utils.pendingActivityIntent(context, fullScreen);

    final Builder notification = new NotificationCompat.Builder(context).setOngoing(true).setLocalOnly(true)
            .setShowWhen(false).setAutoCancel(false).setContentIntent(contentIntent)
            .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS)
            .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_timer)
            .setFullScreenIntent(pendingFullScreen, true)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
            .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background));

    for (Action action : actions) {
        notification.addAction(action);
    }

    if (Utils.isNOrLater()) {
        notification.setCustomContentView(buildChronometer(pname, base, true, stateText));
    } else {
        final CharSequence contentTextPreN = count == 1
                ? context.getString(com.androidinspain.deskclock.R.string.timer_times_up)
                : context.getString(com.androidinspain.deskclock.R.string.timer_multi_times_up, count);

        notification.setContentTitle(stateText).setContentText(contentTextPreN);
    }

    return notification.build();
}

From source file:io.coldstart.android.GCMIntentService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void SendInboxStyleNotification(String alertCount, String alertTime, String hostname,
        String payloadDetails) {//from  w ww  .  j ava  2 s. co m
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    String Line1 = "", Line2 = "", Line3 = "", Line4 = "", Line5 = "";
    String[] separatedLines = payloadDetails.split("\n");

    int payloadLength = separatedLines.length;
    if (payloadLength > 5)
        payloadLength = 5;

    for (int i = 0; i < payloadLength; i++) {
        try {
            switch (i) {
            case 0: {
                Line1 = separatedLines[i];
            }
                break;

            case 1: {
                Line2 = separatedLines[i];
            }
                break;

            case 2: {
                Line3 = separatedLines[i];
            }
                break;

            case 3: {
                Line4 = separatedLines[i];
            }
                break;

            case 4: {
                Line5 = separatedLines[i];
            }
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    Notification notification = new Notification.InboxStyle(
            new Notification.Builder(this).setContentTitle("SNMP trap received")
                    .setContentText(Line1 + " " + Line2 + "...").setSmallIcon(R.drawable.ic_stat_alert)
                    .setVibrate(new long[] { 0, 100, 200, 300 }).setAutoCancel(true).setSound(uri)
                    .setPriority(Notification.PRIORITY_MAX).setTicker("New SNMP traps have been received")
                    .setContentIntent(PendingIntent.getActivity(this, 0,
                            new Intent(this, TrapListActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                                    .putExtra("forceRefresh", true),
                            0))).setBigContentTitle("New SNMP traps have been received")
                                    .setSummaryText("Launch ColdStart.io to Manage These Events").addLine(Line1)
                                    .addLine(Line2).addLine(Line3).addLine(Line4).build();

    notification.defaults |= Notification.DEFAULT_SOUND;

    mNM.notify(43523, notification);
}

From source file:support.plus.reportit.SettingsActivity.java

public Notification getNotification(String content) {
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    final SharedPreferences pref5 = getApplicationContext().getSharedPreferences("soundNotifications",
            MODE_PRIVATE);/*from  w w w.  j a v a  2s . c  o m*/
    String soundUri2 = pref5.getString("alarmSound", String.valueOf(uri));
    Notification.Builder builder = new Notification.Builder(this);
    builder.setContentTitle(getString(R.string.wrap_up));
    builder.setContentText(getString(R.string.wrap_up_desc));
    builder.setVibrate(new long[] { 1000 });
    builder.setSound(Uri.parse(soundUri2));
    builder.setPriority(Notification.PRIORITY_MAX);
    builder.setLights(Color.GREEN, 3000, 3000);
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setAutoCancel(true);
    builder.setContentIntent(PendingIntent.getActivity(this, 1, new Intent(this, AllReportsRV.class),
            PendingIntent.FLAG_UPDATE_CURRENT));
    return builder.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();
    }/*w  w  w . j a  v a2 s .  co  m*/

    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;
}

From source file:com.flyingcrop.ScreenCaptureFragment.java

void notifySS(Bitmap bitmap, String date, String dir) {

    File file = new File(dir);

    if (file.exists()) {
        Log.d("FlyingCrop", "O ficheiro a ser partilhado existe");
    } else {//  w  ww  . j ava  2s  .  c  o  m
        Log.d("FlyingCrop", "O ficheiro a ser partilhado no existe");
    }

    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/png");
    share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

    PendingIntent i = PendingIntent.getActivity(getActivity(), 0,
            Intent.createChooser(share, getResources().getString(R.string.fragment_share)),
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "image/png");
    PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notif = new Notification.Builder(getActivity()).setContentTitle(date + ".png")
            .setContentText(getResources().getString(R.string.fragment_img_preview))
            .addAction(android.R.drawable.ic_menu_share, getResources().getString(R.string.fragment_share), i)
            .setSmallIcon(com.flyingcrop.R.drawable.ab_ico).setLargeIcon(bitmap)
            .setStyle(new Notification.BigPictureStyle().bigPicture(bitmap)).setContentIntent(pendingIntent)
            .setPriority(Notification.PRIORITY_MAX)

            .build();
    final SharedPreferences settings = getActivity().getSharedPreferences("data", 0);

    NotificationManager notificationManager = (NotificationManager) getActivity()
            .getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(1, notif);

    if (settings.getBoolean("vibration", false)) {
        Vibrator v = (Vibrator) this.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(100);
    }
}

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

private void showTimesUpNotification(final Context context, TimerObj timerObj) {
    // Content Intent. When clicked will show the timer full screen
    PendingIntent contentIntent = PendingIntent.getActivity(context, timerObj.mTimerId,
            new Intent(context, TimerAlertFullScreen.class).putExtra(Timers.TIMER_INTENT_EXTRA,
                    timerObj.mTimerId),/*  w w w .  j  a  v a  2 s . com*/
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Add one minute action button
    PendingIntent addOneMinuteAction = PendingIntent.getBroadcast(context, timerObj.mTimerId,
            new Intent(Timers.NOTIF_TIMES_UP_PLUS_ONE).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Add stop/done action button
    PendingIntent stopAction = PendingIntent.getBroadcast(context, timerObj.mTimerId,
            new Intent(Timers.NOTIF_TIMES_UP_STOP).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Notification creation
    Notification notification = new Notification.Builder(context).setContentIntent(contentIntent)
            .addAction(R.drawable.ic_menu_add, context.getResources().getString(R.string.timer_plus_1_min),
                    addOneMinuteAction)
            .addAction(
                    timerObj.getDeleteAfterUse() ? android.R.drawable.ic_menu_close_clear_cancel
                            : R.drawable.ic_stop_normal,
                    timerObj.getDeleteAfterUse() ? context.getResources().getString(R.string.timer_done)
                            : context.getResources().getString(R.string.timer_stop),
                    stopAction)
            .setContentTitle(timerObj.getLabelOrDefault(context))
            .setContentText(context.getResources().getString(R.string.timer_times_up))
            .setSmallIcon(R.drawable.stat_notify_timer).setOngoing(true).setAutoCancel(false)
            .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS).setWhen(0).build();

    // Send the notification using the timer's id to identify the
    // correct notification
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(timerObj.mTimerId,
            notification);
    if (Timers.LOGGING) {
        Log.v(TAG, "Setting times-up notification for " + timerObj.getLabelOrDefault(context) + " #"
                + timerObj.mTimerId);
    }
}

From source file:se.oort.clockify.timer.TimerReceiver.java

private void showTimesUpNotification(final Context context, TimerObj timerObj) {
    // Content Intent. When clicked will show the timer full screen
    PendingIntent contentIntent = PendingIntent.getActivity(context, timerObj.mTimerId,
            new Intent(context, TimerAlertFullScreen.class).putExtra(Timers.TIMER_INTENT_EXTRA,
                    timerObj.mTimerId),/*from w  w w  . j  a  v a 2s  . c o m*/
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Add one minute action button
    PendingIntent addOneMinuteAction = PendingIntent.getBroadcast(context, timerObj.mTimerId,
            new Intent(Timers.NOTIF_TIMES_UP_PLUS_ONE).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Add stop/done action button
    PendingIntent stopAction = PendingIntent.getBroadcast(context, timerObj.mTimerId,
            new Intent(Timers.NOTIF_TIMES_UP_STOP).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Notification creation
    Notification notification = new Notification.Builder(context).setContentIntent(contentIntent)
            .addAction(R.drawable.ic_menu_add, context.getResources().getString(R.string.timer_plus_1_min),
                    addOneMinuteAction)
            .addAction(
                    timerObj.getDeleteAfterUse() ? android.R.drawable.ic_menu_close_clear_cancel
                            : R.drawable.ic_stop_normal,
                    timerObj.getDeleteAfterUse() ? context.getResources().getString(R.string.timer_done)
                            : context.getResources().getString(R.string.timer_stop),
                    stopAction)
            .setContentTitle(timerObj.getLabelOrDefault(context))
            .setContentText(context.getResources().getString(R.string.timer_times_up))
            .setSmallIcon(R.drawable.stat_notify_timer).setOngoing(true).setAutoCancel(false)
            .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS).setWhen(0).build();

    // Send the notification using the timer's id to identify the
    // correct notification
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(timerObj.mTimerId,
            notification);
    if (Timers.LOGGING) {
        Log.v(LOG_TAG, "Setting times-up notification for " + timerObj.getLabelOrDefault(context) + " #"
                + timerObj.mTimerId);
    }
}