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:com.adnanbal.fxdedektifi.forex.presentation.services.NotificationService.java

private void setUpNotificationBuilder(SignalModel signalModel, String status) {

    notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);

    builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_comment_alternative)
            .setVibrate(new long[] { 1000, 1000 }).setSound(System.DEFAULT_NOTIFICATION_URI)
            .setAutoCancel(true);/* w ww  .  j a  v  a 2  s . com*/

    if (status.equals("Open")) {
        builder.setContentTitle("You have a new signal").setContentText(signalModel.getPair() + " : "
                + (signalModel.isBuy_sell() ? "Buy" : "Sell") + " at " + signalModel.getOpeningPrice())
                .setPriority(Notification.PRIORITY_MAX);
    } else if (status.equals("Updated")) {
        builder.setContentTitle("Current signal update").setContentText(signalModel.getPair() + " : "
                + (signalModel.isBuy_sell() ? "Buy" : "Sell") + " at " + signalModel.getOpeningPrice())
                .setPriority(Notification.PRIORITY_MAX);

    } else if (status.equals("Closed")) {
        builder.setContentTitle("Close position signal")
                .setContentText(signalModel.getPair() + " : " + "Close at " + signalModel.getClosingPrice())
                .setPriority(Notification.PRIORITY_MAX);
    }
    //    Intent notificationIntent = new Intent(getContext(), SignalsActivity.class);
    //    PendingIntent contentIntent = PendingIntent.getActivity(getContext(), 0, notificationIntent,
    //        PendingIntent.FLAG_UPDATE_CURRENT);
    //    builder.setContentIntent();

}

From source file:uk.bowdlerize.service.CensorCensusService.java

private void warnOnPrep() {
    mBuilder.setStyle(new NotificationCompat.InboxStyle()
            .setBigContentTitle(getString(R.string.notifTitle) + " - " + getString(R.string.notifRequstURL))
            .addLine(getString(R.string.notifRequesting))
            .addLine("( " + getString(R.string.notifPolling) + " blocked.org.uk )")
            .setSummaryText(Integer.toString(checkedCount) + " " + getString(R.string.notifChecked) + " / "
                    + Integer.toString(censoredCount) + " " + getString(R.string.notifPossBlock)))
            .setSmallIcon(R.drawable.ic_stat_in_progress)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_ooni_large))
            .setPriority(Notification.PRIORITY_MAX)
            .setTicker(getString(R.string.notifTitle) + " - " + getString(R.string.notifRequstURL))
            .setAutoCancel(false);/*from   ww  w.  j  a va2  s .c o  m*/
    mBuilder.setProgress(2, 1, true);
    mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());

    /*Intent newIntent = new Intent();
    newIntent.setAction(ProgressFragment.ORG_BROADCAST);
    newIntent.putExtra(ProgressFragment.ORG_BROADCAST,ProgressFragment.TALKING_TO_ORG);
    sendBroadcast(newIntent);*/
}

From source file:com.wizardsofm.deskclock.data.StopwatchNotificationBuilderN.java

@Override
public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) {
    @StringRes/*from   w ww  .  j a  v a 2s  .c  om*/
    final int eventLabel = com.wizardsofm.deskclock.R.string.label_notification;

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

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

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

    final RemoteViews content = new RemoteViews(pname,
            com.wizardsofm.deskclock.R.layout.chronometer_notif_content);
    content.setChronometer(com.wizardsofm.deskclock.R.id.chronometer, base, null, running);

    final List<Notification.Action> actions = new ArrayList<>(2);

    if (running) {
        // Left button: Pause
        final Intent pause = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

        final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_pause_24dp);
        final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_pause_button);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

        // Right button: Add Lap
        if (DataModel.getDataModel().canAddMoreLaps()) {
            final Intent lap = new Intent(context, StopwatchService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

            final Icon icon2 = Icon.createWithResource(context,
                    com.wizardsofm.deskclock.R.drawable.ic_sw_lap_24dp);
            final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_lap_button);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, lap);
            actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());
        }

        // Show the current lap number if any laps have been recorded.
        final int lapCount = DataModel.getDataModel().getLaps().size();
        if (lapCount > 0) {
            final int lapNumber = lapCount + 1;
            final String lap = res.getString(com.wizardsofm.deskclock.R.string.sw_notification_lap_number,
                    lapNumber);
            content.setTextViewText(com.wizardsofm.deskclock.R.id.state, lap);
            content.setViewVisibility(com.wizardsofm.deskclock.R.id.state, VISIBLE);
        } else {
            content.setViewVisibility(com.wizardsofm.deskclock.R.id.state, GONE);
        }
    } else {
        // Left button: Start
        final Intent start = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

        final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_start_24dp);
        final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_start_button);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, start);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

        // Right button: Reset (dismisses notification and resets stopwatch)
        final Intent reset = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

        final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp);
        final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_reset_button);
        final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset);
        actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

        // Indicate the stopwatch is paused.
        content.setTextViewText(com.wizardsofm.deskclock.R.id.state,
                res.getString(com.wizardsofm.deskclock.R.string.swn_paused));
        content.setViewVisibility(com.wizardsofm.deskclock.R.id.state, VISIBLE);
    }

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

    return new Notification.Builder(context).setLocalOnly(true).setOngoing(running)
            .setCustomContentView(content).setContentIntent(pendingShowApp).setAutoCancel(stopwatch.isPaused())
            .setPriority(Notification.PRIORITY_MAX)
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_stopwatch)
            .setGroup(nm.getStopwatchNotificationGroupKey())
            .setStyle(new Notification.DecoratedCustomViewStyle())
            .setDeleteIntent(Utils.pendingServiceIntent(context, reset))
            .setActions(actions.toArray(new Notification.Action[actions.size()]))
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background))
            .build();
}

From source file:com.example.android.basicsyncadapter.SyncAdapter.java

/**
 * Called by the Android system in response to a request to run the sync adapter. The work required to read data from the network,
 * parse it, and store it in the content provider is done here. Extending AbstractThreadedSyncAdapter ensures that all methods
 * within SyncAdapter run on a background thread. For this reason, blocking I/O and other long-running tasks can be run
 * <em>in situ</em>, and you don't have to set up a separate thread for them.
 *
 * <p>This is where we actually perform any work required to perform a sync. {@link android.content.AbstractThreadedSyncAdapter}
 * guarantees that this will be called on a non-UI thread, so it is safe to peform blocking I/O here.
 *
 * <p>The syncResult argument allows you to pass information back to the method that triggered the sync.
 *//*from   w w w .  j  a  v a 2  s .  co  m*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {
    Log.i(TAG, "Beginning network synchronization");
    try {
        InputStream stream = null;

        try {
            //Log.i(TAG, "Streaming data from network: " + FEED_URL);
            //stream = downloadUrl(location);
            stream = downloadUrl(FEED_URL);
            updateLocalFeedData(stream, syncResult);
        } finally {
            if (stream != null) {
                stream.close();
            }
        }
    } catch (MalformedURLException e) {
        Log.e(TAG, "Feed URL is malformed", e);
        syncResult.stats.numParseExceptions++;
        return;
    } catch (IOException e) {
        Log.e(TAG, "Error reading from network: " + e.toString());
        syncResult.stats.numIoExceptions++;
        return;
    } catch (XmlPullParserException e) {
        Log.e(TAG, "Error parsing feed: " + e.toString());
        syncResult.stats.numParseExceptions++;
        return;
    } catch (ParseException e) {
        Log.e(TAG, "Error parsing feed: " + e.toString());
        syncResult.stats.numParseExceptions++;
        return;
    } catch (RemoteException e) {
        Log.e(TAG, "Error updating database: " + e.toString());
        syncResult.databaseError = true;
        return;
    } catch (OperationApplicationException e) {
        Log.e(TAG, "Error updating database: " + e.toString());
        syncResult.databaseError = true;
        return;
    }
    Log.i(TAG, "Network synchronization complete");

    //Throw notification

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getContext())
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Alerta de cicln tropical")
            .setContentText("Hello World!").setAutoCancel(true).setLights(0xff00ff00, 300, 100)
            .setPriority(Notification.PRIORITY_MAX);

    Intent resultIntent = new Intent(getContext(), EntryListActivity.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(getContext(), 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    //Add sound
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    //Add vibrate pattern
    long[] pattern = { 0, 200, 500 };

    mBuilder.setVibrate(pattern);
    mBuilder.setSound(alarmSound);
    mBuilder.setContentIntent(resultPendingIntent);

    int mNotificationId = 001;
    NotificationManager mNotifyMgr = (NotificationManager) getContext()
            .getSystemService(Service.NOTIFICATION_SERVICE);
    mNotifyMgr.notify(mNotificationId, mBuilder.build());

    //Wake screen
    /*WakeLock screenOn = ((PowerManager)getContext().getSystemService(Service.POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK| PowerManager.ACQUIRE_CAUSES_WAKEUP, "example");
    screenOn.acquire();
            
    long endTime = System.currentTimeMillis() + 6*1000;
    while (System.currentTimeMillis() < endTime) {
    synchronized (this) {
        try {
            wait(endTime - System.currentTimeMillis());
        } catch (Exception e) {
        }
    }
    }
            
    screenOn.release();*/
}

From source file:com.cmput301w17t07.moody.AchievementController.java

/**
 * this method is used to send a notification to the android phone once a achievement has been
 * unlocked and then displays the information of the achievement <br>
 * @param context <br>/*from w  w w . j a v  a  2 s .co  m*/
 * @param achievement <br>
 */
public static void displayAchievement(Context context, String achievement) {
    NotificationCompat.Builder b = new NotificationCompat.Builder(context);
    b.setAutoCancel(true).setDefaults(NotificationCompat.DEFAULT_ALL).setWhen(System.currentTimeMillis())
            .setSmallIcon(R.drawable.achievement2).setTicker("{your tiny message}").setContentTitle("Moody")
            .setContentText(achievement).setContentInfo("INFO").setPriority(Notification.PRIORITY_MAX);

    NotificationManager nm = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    nm.notify(1, b.build());
}

From source file:uk.bowdlerize.service.CensorCensusService.java

private void warnOnError() {
    mBuilder.setStyle(new NotificationCompat.InboxStyle()
            .setBigContentTitle(getString(R.string.notifTitle) + " - No URLs")
            .addLine(getString(R.string.notifNoURLToCheck)).addLine(getString(R.string.notifAddURL))
            .setSummaryText(Integer.toString(checkedCount) + " " + getString(R.string.notifChecked) + " / "
                    + Integer.toString(censoredCount) + " " + getString(R.string.notifPossBlock)))
            .setSmallIcon(R.drawable.ic_stat_waiting)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_ooni_large))
            .setPriority(Notification.PRIORITY_MAX).setTicker(getString(R.string.notifTitle) + " - No URLs")
            .setAutoCancel(false);// w  ww  . j a  v a  2  s.  co m
    mBuilder.setProgress(0, 0, false);

    mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());

    Intent newIntent = new Intent();
    newIntent.setAction(ProgressFragment.ORG_BROADCAST);
    newIntent.putExtra(ProgressFragment.ORG_BROADCAST, ProgressFragment.NO_URLS);
    sendBroadcast(newIntent);
}

From source file:ua.org.gdg.devfest.iosched.service.SessionAlarmService.java

private void notifySession(final long sessionStart, final long sessionEnd, final long alarmOffset) {
    long currentTime;
    if (sessionStart < (currentTime = UIUtils.getCurrentTime(this)))
        return;/*from  w ww.j  ava  2  s  .  com*/

    // Avoid repeated notifications.
    if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this,
            ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd))) {
        return;
    }

    final ContentResolver cr = getContentResolver();
    final Uri starredBlockUri = ScheduleContract.Blocks
            .buildStarredSessionsUri(ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd));
    Cursor c = cr.query(starredBlockUri, SessionDetailQuery.PROJECTION, null, null, null);
    int starredCount = 0;
    ArrayList<String> starredSessionTitles = new ArrayList<String>();
    ArrayList<String> starredSessionRoomIds = new ArrayList<String>();
    String sessionId = null; // needed to get session track icon
    while (c.moveToNext()) {
        sessionId = c.getString(SessionDetailQuery.SESSION_ID);
        starredCount = c.getInt(SessionDetailQuery.NUM_STARRED_SESSIONS);
        starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE));
        starredSessionRoomIds.add(c.getString(SessionDetailQuery.ROOM_ID));
    }
    if (starredCount < 1) {
        return;
    }

    // Generates the pending intent which gets fired when the user taps on the notification.
    // NOTE: Use TaskStackBuilder to comply with Android's design guidelines
    // related to navigation from notifications.
    PendingIntent pi = TaskStackBuilder.create(this).addNextIntent(new Intent(this, HomeActivity.class))
            .addNextIntent(new Intent(Intent.ACTION_VIEW, starredBlockUri))
            .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentText;
    int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000;
    if (minutesLeft < 1) {
        minutesLeft = 1;
    }

    if (starredCount == 1) {
        contentText = res.getString(R.string.session_notification_text_1, minutesLeft);
    } else {
        contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft,
                starredCount - 1);
    }

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText)
            .setTicker(res.getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount))
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS,
                    SessionAlarmService.NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(R.drawable.ic_stat_droidconuk).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
    if (starredCount == 1) {
        // get the track icon to show as the notification big picture
        Uri tracksUri = ScheduleContract.Sessions.buildTracksDirUri(sessionId);
        Cursor tracksCursor = cr.query(tracksUri, SessionTrackQuery.PROJECTION, null, null, null);
        if (tracksCursor.moveToFirst()) {
            String trackName = tracksCursor.getString(SessionTrackQuery.TRACK_NAME);
            int trackColour = tracksCursor.getInt(SessionTrackQuery.TRACK_COLOR);
            Bitmap trackIcon = UIUtils.getTrackIconSync(getApplicationContext(), trackName, trackColour);
            if (trackIcon != null) {
                notifBuilder.setLargeIcon(trackIcon);
            }
        }
    }
    if (minutesLeft > 5) {
        notifBuilder.addAction(R.drawable.ic_alarm_holo_dark,
                String.format(res.getString(R.string.snooze_x_min), 5),
                createSnoozeIntent(sessionStart, sessionEnd, 5));
    }
    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(res.getQuantityString(R.plurals.session_notification_title, starredCount,
                    minutesLeft, starredCount));

    // Adds starred sessions starting at this time block to the notification.
    for (int i = 0; i < starredCount; i++) {
        richNotification.addLine(starredSessionTitles.get(i));
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, richNotification.build());
}

From source file:com.google.android.apps.iosched.calendar.SessionAlarmService.java

/**
 * Constructs and triggers system notification for when starred sessions are about to begin.
 *//*from w  w w  .  ja v a 2  s  .co  m*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void notifySession(final long sessionStart, final long sessionEnd, final long alarmOffset) {
    long currentTime = System.currentTimeMillis();
    if (sessionStart < currentTime) {
        return;
    }

    // Avoid repeated notifications.
    if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this,
            ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd))) {
        return;
    }

    final ContentResolver resolver = getContentResolver();
    final Uri starredBlockUri = ScheduleContract.Blocks
            .buildStarredSessionsUri(ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd));
    Cursor cursor = resolver.query(starredBlockUri, new String[] { ScheduleContract.Blocks.NUM_STARRED_SESSIONS,
            ScheduleContract.Sessions.SESSION_TITLE }, null, null, null);
    int starredCount = 0;
    ArrayList<String> starredSessionTitles = new ArrayList<String>();
    while (cursor.moveToNext()) {
        starredSessionTitles.add(cursor.getString(1));
        starredCount = cursor.getInt(0);
    }

    if (starredCount < 1) {
        return;
    }

    // Generates the pending intent which gets fired when the user touches on the notification.
    Intent sessionIntent = new Intent(Intent.ACTION_VIEW, starredBlockUri);
    sessionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pi = PendingIntent.getActivity(this, 0, sessionIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentText;
    int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000;
    if (minutesLeft < 1) {
        minutesLeft = 1;
    }

    if (starredCount == 1) {
        contentText = res.getString(R.string.session_notification_text_1, minutesLeft);
    } else {
        contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft,
                starredCount - 1);
    }

    // Construct a notification. Use Jelly Bean (API 16) rich notifications if possible.
    Notification notification;
    if (UIUtils.hasJellyBean()) {
        // Rich notifications
        Notification.Builder builder = new Notification.Builder(this)
                .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText)
                .setTicker(res
                        .getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount))
                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR,
                        SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS)
                .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi)
                .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
        if (minutesLeft > 5) {
            builder.addAction(R.drawable.ic_alarm_holo_dark,
                    String.format(res.getString(R.string.snooze_x_min), 5),
                    createSnoozeIntent(sessionStart, sessionEnd, 5));
        }
        Notification.InboxStyle richNotification = new Notification.InboxStyle(builder)
                .setBigContentTitle(res.getQuantityString(R.plurals.session_notification_title, starredCount,
                        minutesLeft, starredCount));

        // Adds starred sessions starting at this time block to the notification.
        for (int i = 0; i < starredCount; i++) {
            richNotification.addLine(starredSessionTitles.get(i));
        }
        notification = richNotification.build();

    } else {
        // Pre-Jelly Bean non-rich notifications
        notification = new NotificationCompat.Builder(this).setContentTitle(starredSessionTitles.get(0))
                .setContentText(contentText)
                .setTicker(res
                        .getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount))
                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR,
                        SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS)
                .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi).getNotification();
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, notification);
}

From source file:com.alucas.snorlax.module.feature.encounter.EncounterNotification.java

@SuppressWarnings("deprecation")
void show(int pokemonNumber, String pokemonName, Gender gender, double iv, int attack, int defense, int stamina,
        int cp, double level, int hp, double baseWeight, double weight, double baseHeight, double height,
        MoveSettings fastMove, MoveSettings chargeMove, double fleeRate, double pokeRate, double greatRate,
        double ultraRate, PokemonType type1, PokemonType type2, PokemonRarity pokemonClass) {
    final double weightRatio = weight / baseWeight;
    final double heightRatio = height / baseHeight;
    final MODIFIER resourceModifier = (pokemonNumber == PokemonId.PIKACHU_VALUE ? MODIFIER.FAN
            : pokemonNumber == PokemonId.RATTATA_VALUE && heightRatio < 0.80 ? MODIFIER.YOUNGSTER
                    : pokemonNumber == PokemonId.MAGIKARP_VALUE && weightRatio > 1.30 ? MODIFIER.FISHERMAN
                            : MODIFIER.NO);

    final String genderSymbol = PokemonFormat.formatGender(mResources, gender);
    final String fastMoveName = PokemonFormat.formatMove(fastMove.getMovementId());
    final String chargeMoveName = PokemonFormat.formatMove(chargeMove.getMovementId());
    final String fastMoveTypeName = PokemonFormat.formatType(fastMove.getPokemonType());
    final String chargeMoveTypeName = PokemonFormat.formatType(chargeMove.getPokemonType());
    final String fastMoveTypeSymbol = TYPE_SYMBOL.containsKey(fastMove.getPokemonType())
            ? mResources.getString(TYPE_SYMBOL.get(fastMove.getPokemonType()))
            : "?";
    final String chargeMoveTypeSymbol = TYPE_SYMBOL.containsKey(chargeMove.getPokemonType())
            ? mResources.getString(TYPE_SYMBOL.get(chargeMove.getPokemonType()))
            : "?";

    final Map<String, Pair<String, Integer>> symbols = getSymbolReplacementTable();
    new Handler(Looper.getMainLooper()).post(() -> {
        Notification notification = new NotificationCompat.Builder(mContext)
                .setSmallIcon(R.drawable.ic_pokeball)
                .setLargeIcon(Bitmap.createScaledBitmap(
                        BitmapFactory.decodeResource(mResources,
                                Resource.getPokemonResourceId(mContext, mResources, pokemonNumber,
                                        resourceModifier)),
                        Resource.getLargeIconWidth(mResources), Resource.getLargeIconHeight(mResources), false))
                .setContentTitle(EncounterFormat.format(
                        mContext.getString(R.string.notification_title, genderSymbol, pokemonName, cp, level),
                        symbols))/* ww  w. ja  v a 2  s  . co m*/
                .setContentText(EncounterFormat.format(mContext.getString(R.string.notification_content, iv,
                        fleeRate, pokeRate, greatRate, ultraRate), symbols))
                .setStyle(new NotificationCompat.InboxStyle()
                        .addLine(EncounterFormat
                                .format(mContext.getString(R.string.notification_category_stats_content_iv, iv,
                                        attack, defense, stamina), symbols))
                        .addLine(EncounterFormat.format(mContext.getString(
                                R.string.notification_category_stats_content_hp, hp, fleeRate), symbols))
                        .addLine(EncounterFormat
                                .bold(mContext.getString(R.string.notification_category_moves_title)))
                        .addLine(EncounterFormat
                                .format(mContext.getString(R.string.notification_category_moves_fast,
                                        fastMoveName, fastMoveTypeName, fastMove.getPower()), symbols))
                        .addLine(
                                EncounterFormat.format(
                                        mContext.getString(R.string.notification_category_moves_charge,
                                                chargeMoveName, chargeMoveTypeName, chargeMove.getPower()),
                                        symbols))
                        .addLine(EncounterFormat
                                .bold(mContext.getString(R.string.notification_categoty_catch_title)))
                        .addLine(EncounterFormat
                                .format(mContext.getString(R.string.notification_categoty_catch_content,
                                        pokeRate, greatRate, ultraRate), symbols))
                        .setSummaryText(getFooter(type1, type2, pokemonClass)))
                .setColor(ContextCompat.getColor(mContext, R.color.red_700)).setAutoCancel(true)
                .setVibrate(new long[] { 0 }).setPriority(Notification.PRIORITY_MAX)
                .setCategory(NotificationCompat.CATEGORY_ALARM).build();

        hideIcon(notification);

        mNotificationManager.notify(NotificationId.ID_ENCOUNTER, notification);
    });
}

From source file:org.catrobat.catroid.utils.StatusBarNotificationManager.java

public void showUploadRejectedNotification(int id, int statusCode, String serverAnswer, Bundle bundle) {
    NotificationData notificationData = notificationDataMap.get(id);

    if (notificationData == null) {
        Log.d(TAG, "NotificationData is null.");
        return;/*from   w  w w.ja v a2  s . c o m*/
    }
    NotificationCompat.Builder notificationBuilder = notificationData.getNotificationBuilder();
    notificationData.setNotificationTextDone(serverAnswer);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notificationBuilder.setContentTitle(context.getResources().getText(R.string.notification_upload_rejected))
            .setContentText(serverAnswer)
            .setTicker(context.getResources().getText(R.string.notification_upload_rejected))
            .setSound(alarmSound).setStyle(new NotificationCompat.BigTextStyle().bigText(serverAnswer))
            .setProgress(0, 0, false).setAutoCancel(true).setPriority(Notification.PRIORITY_MAX)
            .setOngoing(false);

    switch (statusCode) {
    case Constants.STATUS_CODE_INTERNAL_SERVER_ERROR:
    case Constants.STATUS_CODE_UPLOAD_MISSING_DATA:
    case Constants.STATUS_CODE_UPLOAD_INVALID_CHECKSUM:
    case Constants.STATUS_CODE_UPLOAD_COPY_FAILED:
    case Constants.STATUS_CODE_UPLOAD_UNZIP_FAILED:
    case Constants.STATUS_CODE_UPLOAD_MISSING_XML:
    case Constants.STATUS_CODE_UPLOAD_RENAME_FAILED:
    case Constants.STATUS_CODE_UPLOAD_SAVE_THUMBNAIL_FAILED:
        Intent actionIntentRetryUpload = new Intent(context, NotificationActionService.class)
                .setAction(ACTION_RETRY_UPLOAD);
        actionIntentRetryUpload.putExtra("bundle", bundle);

        PendingIntent actionPendingIntentRetryUpload = PendingIntent.getService(context, id,
                actionIntentRetryUpload, PendingIntent.FLAG_CANCEL_CURRENT);
        notificationBuilder.addAction(android.R.drawable.ic_popup_sync,
                context.getResources().getString(R.string.notification_upload_retry),
                actionPendingIntentRetryUpload);

        Intent actionIntentCancelUpload = new Intent(context, NotificationActionService.class)
                .setAction(ACTION_CANCEL_UPLOAD);
        actionIntentCancelUpload.putExtra("bundle", bundle);
        PendingIntent actionPendingIntentCancelUpload = PendingIntent.getService(context, id,
                actionIntentCancelUpload, PendingIntent.FLAG_ONE_SHOT);
        notificationBuilder.addAction(android.R.drawable.ic_menu_close_clear_cancel,
                context.getResources().getString(R.string.cancel_button), actionPendingIntentCancelUpload);

        break;
    case Constants.STATUS_CODE_UPLOAD_MISSING_CHECKSUM:
    case Constants.STATUS_CODE_UPLOAD_OLD_CATROBAT_LANGUAGE:
    case Constants.STATUS_CODE_UPLOAD_OLD_CATROBAT_VERSION:
        Intent actionIntentUpdatePocketCodeVersion = new Intent(context, NotificationActionService.class)
                .setAction(ACTION_UPDATE_POCKET_CODE_VERSION).putExtra("notificationId", id);
        PendingIntent actionPendingIntentUpdatePocketCodeVersion = PendingIntent.getService(context, id,
                actionIntentUpdatePocketCodeVersion, PendingIntent.FLAG_ONE_SHOT);
        notificationBuilder.addAction(R.drawable.ic_launcher,
                context.getResources().getString(R.string.notification_open_play_store),
                actionPendingIntentUpdatePocketCodeVersion);
        break;

    default:
        notificationDataMap.put(id, notificationData);
        Intent openIntent = new Intent(context, MainMenuActivity.class);
        openIntent.setAction(Intent.ACTION_MAIN).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                .putExtra(EXTRA_PROJECT_NAME, bundle.getString("projectName"));

        PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, openIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        notificationData.setPendingIntent(pendingIntent);
        showOrUpdateNotification(id, MAXIMUM_PERCENT);
        return;
    }

    notificationBuilder.setContentIntent(notificationData.getPendingIntent());

    notificationDataMap.put(id, notificationData);
    notificationManager.notify(id, notificationBuilder.build());
}