示例#1
0
  private void Vibrate(
      Context ctx,
      AlertType alert,
      String bgValue,
      Boolean overrideSilent,
      int timeFromStartPlaying) {
    Log.d(TAG, "Vibrate called timeFromStartPlaying = " + timeFromStartPlaying);
    Log.d("ALARM", "setting vibrate alarm");
    int profile = getAlertProfile(ctx);

    // We use timeFromStartPlaying as a way to force vibrating/ non vibrating...
    if (profile != ALERT_PROFILE_ASCENDING) {
      // We start from the non ascending part...
      timeFromStartPlaying = MAX_ASCENDING;
    }

    String title = bgValue + " " + alert.name;
    String content = "BG LEVEL ALERT: " + bgValue;
    Intent intent = new Intent(ctx, SnoozeActivity.class);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(ctx)
            .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
            .setContentTitle(title)
            .setContentText(content)
            .setContentIntent(notificationIntent(ctx, intent))
            .setDeleteIntent(snoozeIntent(ctx));
    if (profile != ALERT_PROFILE_VIBRATE_ONLY && profile != ALERT_PROFILE_SILENT) {
      if (timeFromStartPlaying >= MAX_VIBRATING) {
        // Before this, we only vibrate...
        float volumeFrac =
            (float) (timeFromStartPlaying - MAX_VIBRATING) / (MAX_ASCENDING - MAX_VIBRATING);
        volumeFrac = Math.min(volumeFrac, 1);
        if (profile == ALERT_PROFILE_MEDIUM) {
          volumeFrac = (float) 0.7;
        }
        Log.d(TAG, "Vibrate volumeFrac = " + volumeFrac);
        boolean isRingTone = EditAlertActivity.isPathRingtone(ctx, alert.mp3_file);
        if (isRingTone && !overrideSilent) {
          builder.setSound(Uri.parse(alert.mp3_file));
        } else {
          if (overrideSilent || isLoudPhone(ctx)) {
            PlayFile(ctx, alert.mp3_file, volumeFrac);
          }
        }
      }
    }
    if (profile != ALERT_PROFILE_SILENT && alert.vibrate) {
      builder.setVibrate(Notifications.vibratePattern);
    }
    NotificationManager mNotifyMgr =
        (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotifyMgr.cancel(Notifications.exportAlertNotificationId);
    mNotifyMgr.notify(Notifications.exportAlertNotificationId, builder.build());
  }
示例#2
0
  public static void postAppInstalledNotification(Context context, String packageName) {
    Intent neverShowAgain = new Intent(MAXLOCK_ACTION_NEVER_SHOW_AGAIN);
    neverShowAgain.setClass(context, NewAppInstalledBroadcastReceiver.class);
    Intent lockApp = new Intent(MAXLOCK_ACTION_LOCK_APP);
    lockApp.setClass(context, NewAppInstalledBroadcastReceiver.class);
    lockApp.putExtra(EXTRA_PACKAGE_NAME, packageName);

    String appName;
    try {
      appName =
          context
              .getPackageManager()
              .getApplicationInfo(packageName, 0)
              .loadLabel(context.getPackageManager())
              .toString();
    } catch (PackageManager.NameNotFoundException e) {
      appName = packageName;
    }

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.notification_lock_new_app_title))
            .setContentText(appName)
            .setSmallIcon(R.drawable.ic_lock_48dp)
            .setAutoCancel(true)
            .addAction(
                new NotificationCompat.Action(
                    0,
                    context.getString(R.string.notification_lock_new_app_action_never_again),
                    PendingIntent.getBroadcast(
                        context, 0, neverShowAgain, PendingIntent.FLAG_UPDATE_CURRENT)))
            .addAction(
                new NotificationCompat.Action(
                    0,
                    context.getString(R.string.notification_lock_new_app_action_lock),
                    PendingIntent.getBroadcast(
                        context, 0, lockApp, PendingIntent.FLAG_UPDATE_CURRENT)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      builder
          .setPriority(NotificationCompat.PRIORITY_HIGH)
          .setCategory(NotificationCompat.CATEGORY_RECOMMENDATION)
          .setColor(ContextCompat.getColor(context, R.color.accent));
      try {
        builder.setVibrate(new long[0]);
      } catch (SecurityException e) {
        e.printStackTrace();
      }
    }
    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.notify(APP_INSTALLED_NOTIFICATION_ID, builder.build());
  }
示例#3
0
 protected void showSimpleNotification(String title, String message) {
   SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(this);
   // Don't show notification if disabled in preferences
   if (Integer.parseInt(prefs.getString("minimumCardsDueForNotification", "0")) <= 1000000) {
     // Use the title as the ticker unless the title is simply "AnkiDroid"
     String ticker = title;
     if (title.equals(getResources().getString(R.string.app_name))) {
       ticker = message;
     }
     // Build basic notification
     NotificationCompat.Builder builder =
         new NotificationCompat.Builder(this)
             .setSmallIcon(R.drawable.ic_stat_notify)
             .setContentTitle(title)
             .setContentText(message)
             .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
             .setTicker(ticker);
     // Enable vibrate and blink if set in preferences
     if (prefs.getBoolean("widgetVibrate", false)) {
       builder.setVibrate(new long[] {1000, 1000, 1000});
     }
     if (prefs.getBoolean("widgetBlink", false)) {
       builder.setLights(Color.BLUE, 1000, 1000);
     }
     // Creates an explicit intent for an Activity in your app
     Intent resultIntent = new Intent(this, DeckPicker.class);
     resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
     PendingIntent resultPendingIntent =
         PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
     if (resultPendingIntent == null) {
       // PendingIntent could not be created... probably something wrong with the extras
       // try again without the extras, though the original dialog will not be shown when app
       // started
       Timber.e("AnkiActivity.showSimpleNotification() failed due to null PendingIntent");
       resultIntent = new Intent(this, DeckPicker.class);
       resultPendingIntent =
           PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
     }
     builder.setContentIntent(resultPendingIntent);
     NotificationManager notificationManager =
         (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     // mId allows you to update the notification later on.
     notificationManager.notify(SIMPLE_NOTIFICATION_ID, builder.build());
   }
 }
 private void setNotificationVibration(
     Bundle extras, Boolean vibrateOption, NotificationCompat.Builder mBuilder) {
   String vibrationPattern = extras.getString(VIBRATION_PATTERN);
   if (vibrationPattern != null) {
     String[] items = vibrationPattern.replaceAll("\\[", "").replaceAll("\\]", "").split(",");
     long[] results = new long[items.length];
     for (int i = 0; i < items.length; i++) {
       try {
         results[i] = Long.parseLong(items[i].trim());
       } catch (NumberFormatException nfe) {
       }
     }
     mBuilder.setVibrate(results);
   } else {
     if (vibrateOption) {
       mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
     }
   }
 }
  /**
   * Create a notification
   *
   * @param context The application context
   * @param title Notification title
   * @param content Notification content.
   */
  public static void createNotification(
      final Context context, final String title, final String content, int id) {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
            .setColor(ContextCompat.getColor(context, R.color.main_theme))
            .extend(new NotificationCompat.WearableExtender().setHintShowBackgroundOnly(true))
            .setContentText(content)
            .setAutoCancel(true)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0))
            .setSmallIcon(R.drawable.ic_stat_kuas_ap);

    builder.setVibrate(vibrationPattern);
    builder.setLights(Color.GREEN, 800, 800);
    builder.setDefaults(Notification.DEFAULT_SOUND);

    notificationManager.notify(id, builder.build());
  }
示例#6
0
  // NOTIFICATION!
  public void startNotification() {
    String titlee = "Hey Good Looking";
    String contente = "Whats cooking?";

    File f = getBaseContext().getFileStreamPath("Done.txt");
    if (!f.exists()) return;

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon))
            .setContentTitle(titlee)
            .setContentText(contente)
            .setAutoCancel(true)
            .setVibrate(new long[100])
            .setPriority(Notification.PRIORITY_MAX);

    if (Build.VERSION.SDK_INT >= 21) mBuilder.setVibrate(new long[0]);

    Intent resultIntent = new Intent(this, OpenCamera.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.addAction(0, "Take a Selfie!", resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(0, mBuilder.build());

    try {
      FileOutputStream fos = openFileOutput("Done.txt", Context.MODE_APPEND);
      fos.write(("yio").getBytes());
      fos.close();
    } catch (Exception e) {
    }
  }
示例#7
0
 @Override
 public Builder setVibrate(long[] pattern) {
   super.setVibrate(pattern);
   return this;
 }
示例#8
0
  public static void notify(
      String title,
      String text,
      String bigText,
      Boolean autoCancel,
      int id,
      String accountKey,
      String type,
      long postId,
      Context context) {
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setTicker(text)
            .setSmallIcon(R.drawable.notification_default)
            .setAutoCancel(autoCancel)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(title)
            .setContentText(text)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    boolean isActive = AppSettings.get().isPebbleNotificationsEnabled();
    if (isActive == true) {
      App.pebbleNotifications.notify(title, text);
      //  App.pebbleNotifications.notify(title, text);
    }

    if (AppSettings.get().isNotificationVibrationEnabled()) {
      long[] pattern = {200, 500, 200};
      builder.setVibrate(pattern);
    }

    Uri ringtone = AppSettings.get().getRingtoneUri();
    if (ringtone != null) {
      builder.setSound(ringtone);
    }

    Intent resultIntent = new Intent(context, HomeActivity.class);
    resultIntent.putExtra("account_key", accountKey);
    resultIntent.putExtra("notification_type", type);
    resultIntent.putExtra("notification_post_id", postId);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(HomeActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    int requestCode = (int) (Math.random() * Integer.MAX_VALUE);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(resultPendingIntent);

    Intent deleteIntent = new Intent(context, DeleteNotificationsReceiver.class);
    deleteIntent.putExtra("account_key", accountKey);
    deleteIntent.putExtra("notification_post_id", postId);
    deleteIntent.putExtra("notification_type", type);
    requestCode = (int) (Math.random() * Integer.MAX_VALUE);
    PendingIntent deletePendingIntent =
        PendingIntent.getBroadcast(context, requestCode, deleteIntent, 0);

    builder.setDeleteIntent(deletePendingIntent);

    saveLastNotificationDisplayed(context, accountKey, type, postId);

    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(id, builder.build());
  }
  public void showNotifications(List<String> contacts) {
    if (!(ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationsActivity)) {
      Conversation[] conversations =
          Database.getInstance(applicationContext).getConversations(preferences.getDid());
      for (Conversation conversation : conversations) {
        if (!conversation.isUnread()
            || !contacts.contains(conversation.getContact())
            || (ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationActivity
                && ((ConversationActivity) ActivityMonitor.getInstance().getCurrentActivity())
                    .getContact()
                    .equals(conversation.getContact()))) {
          continue;
        }

        String smsContact = Utils.getContactName(applicationContext, conversation.getContact());
        if (smsContact == null) {
          smsContact = Utils.getFormattedPhoneNumber(conversation.getContact());
        }

        String allSmses = "";
        String mostRecentSms = "";
        boolean initial = true;
        for (Message message : conversation.getMessages()) {
          if (message.getType() == Message.Type.INCOMING && message.isUnread()) {
            if (initial) {
              allSmses = message.getText();
              mostRecentSms = message.getText();
              initial = false;
            } else {
              allSmses = message.getText() + "\n" + allSmses;
            }
          } else {
            break;
          }
        }

        NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(applicationContext);

        notificationBuilder.setContentTitle(smsContact);
        notificationBuilder.setContentText(mostRecentSms);
        notificationBuilder.setSmallIcon(R.drawable.ic_chat_white_24dp);
        notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
        notificationBuilder.setSound(
            Uri.parse(Preferences.getInstance(applicationContext).getNotificationSound()));
        notificationBuilder.setLights(0xFFAA0000, 1000, 5000);
        if (Preferences.getInstance(applicationContext).getNotificationVibrateEnabled()) {
          notificationBuilder.setVibrate(new long[] {0, 250, 250, 250});
        } else {
          notificationBuilder.setVibrate(new long[] {0});
        }
        notificationBuilder.setColor(0xFFAA0000);
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(allSmses));

        Bitmap largeIconBitmap;
        try {
          largeIconBitmap =
              MediaStore.Images.Media.getBitmap(
                  applicationContext.getContentResolver(),
                  Uri.parse(
                      Utils.getContactPhotoUri(applicationContext, conversation.getContact())));
          largeIconBitmap = Bitmap.createScaledBitmap(largeIconBitmap, 256, 256, false);
          largeIconBitmap = Utils.applyCircularMask(largeIconBitmap);
          notificationBuilder.setLargeIcon(largeIconBitmap);
        } catch (Exception ignored) {

        }

        Intent intent = new Intent(applicationContext, ConversationActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(
            applicationContext.getString(R.string.conversation_extra_contact),
            conversation.getContact());
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(applicationContext);
        stackBuilder.addParentStack(ConversationActivity.class);
        stackBuilder.addNextIntent(intent);
        notificationBuilder.setContentIntent(
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT));

        Intent replyIntent = new Intent(applicationContext, ConversationQuickReplyActivity.class);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
          replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
        } else {
          //noinspection deprecation
          replyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        }
        replyIntent.putExtra(
            applicationContext.getString(R.string.conversation_extra_contact),
            conversation.getContact());
        PendingIntent replyPendingIntent =
            PendingIntent.getActivity(
                applicationContext, 0, replyIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        NotificationCompat.Action.Builder replyAction =
            new NotificationCompat.Action.Builder(
                R.drawable.ic_reply_white_24dp,
                applicationContext.getString(R.string.notifications_button_reply),
                replyPendingIntent);
        notificationBuilder.addAction(replyAction.build());

        Intent markAsReadIntent = new Intent(applicationContext, MarkAsReadReceiver.class);
        markAsReadIntent.putExtra(
            applicationContext.getString(R.string.conversation_extra_contact),
            conversation.getContact());
        PendingIntent markAsReadPendingIntent =
            PendingIntent.getBroadcast(
                applicationContext, 0, markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        NotificationCompat.Action.Builder markAsReadAction =
            new NotificationCompat.Action.Builder(
                R.drawable.ic_drafts_white_24dp,
                applicationContext.getString(R.string.notifications_button_mark_read),
                markAsReadPendingIntent);
        notificationBuilder.addAction(markAsReadAction.build());

        int id;
        if (notificationIds.get(conversation.getContact()) != null) {
          id = notificationIds.get(conversation.getContact());
        } else {
          id = notificationIdCount++;
          notificationIds.put(conversation.getContact(), id);
        }
        NotificationManager notificationManager =
            (NotificationManager) applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(id, notificationBuilder.build());
      }
    }
  }
示例#10
0
  private boolean updateNotification(final Context context) {
    Log.d(TAG, "updateNotification()");
    lastUpdate = System.currentTimeMillis();
    NotificationManager nm =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    ArrayList<Timer> timers = new ArrayList<Timer>();
    mNow = System.currentTimeMillis();
    mNextTarget = 0;
    boolean alert = false;
    Log.d(TAG, "mNow: " + mNow);

    for (int j = 0; j < Timer.TIMER_IDS.length; j++) {
      Timer t = new Timer(context, j);
      timers.add(t);
      long tt = t.getTarget();
      Log.d(TAG, "target(" + j + "): " + tt);

      if (tt > 0) {
        if (mNextTarget == 0 || tt < mNextTarget) {
          mNextTarget = tt;
        }
        if (tt < mNow) {
          alert = true;
          t.reset(context);
        }
      }
    }
    Log.d(TAG, "mNextTarget: " + mNextTarget);

    NotificationCompat.Builder b = new NotificationCompat.Builder(context);
    b.setPriority(1000);
    Intent i = new Intent(context, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    b.setContentIntent(PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT));

    b.setContentTitle(context.getString(R.string.app_name));
    b.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
    b.setSmallIcon(R.drawable.ic_stat_timer);
    b.setAutoCancel(false);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // GB-
      b.setContentText(
          context.getString(
              R.string.notification_text,
              timers.get(0).getFormatted(),
              timers.get(1).getFormatted(),
              timers.get(2).getFormatted()));
    } else { // HC+
      RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.notification);
      for (int j = 0; j < Timer.TIMER_IDS.length; j++) {
        v.setTextViewText(Timer.TIMER_IDS[j], timers.get(j).getFormatted().toString());
        Intent ij = new Intent(Timer.TIMER_KEYS[j], null, context, UpdateReceiver.class);
        v.setOnClickPendingIntent(
            Timer.TIMER_IDS[j],
            PendingIntent.getBroadcast(context, 0, ij, PendingIntent.FLAG_UPDATE_CURRENT));
      }
      v.setOnClickPendingIntent(
          R.id.settings,
          PendingIntent.getActivity(
              context,
              0,
              new Intent(context, SettingsActivity.class),
              PendingIntent.FLAG_UPDATE_CURRENT));
      b.setContent(v);
    }

    if (mNextTarget <= 0 && !alert) {
      // we don't need any notification
      b.setOngoing(false);
      nm.notify(0, b.build());
      return false;
    } else if (alert) {
      // show notification without running Timer
      b.setOngoing(mNextTarget > 0);
      SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
      if (p.getBoolean("vibrate", true)) {
        b.setVibrate(VIBRATE);
      }
      String n = p.getString("notification", null);
      if (n == null) { // default
        b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
      } else if (n.length() > 1) {
        try {
          b.setSound(Uri.parse(n));
        } catch (Exception e) {
          Log.e(TAG, "invalid notification uri", e);
          b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
      } // else: silent
      nm.notify(0, b.build());
      return true;
    } else {
      // show notification with running Timer
      b.setOngoing(true);
      nm.notify(0, b.build());
      return true;
    }
  }
  private void onNotify(
      final SharedPreferences prefs, final Cursor upcomingEpisodes, int count, long latestAirtime) {
    final Context context = getApplicationContext();
    CharSequence tickerText = "";
    CharSequence contentTitle = "";
    CharSequence contentText = "";
    PendingIntent contentIntent = null;

    // notification sound
    final String ringtoneUri = NotificationSettings.getNotificationsRingtone(context);
    // vibration
    final boolean isVibrating = NotificationSettings.isNotificationVibrating(context);

    if (count == 1) {
      // notify in detail about one episode
      upcomingEpisodes.moveToFirst();
      final String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE);
      final String airs =
          Utils.formatToTimeAndDay(upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS), this)[
              0];
      final String network = upcomingEpisodes.getString(NotificationQuery.NETWORK);

      tickerText = getString(R.string.upcoming_show, showTitle);
      contentTitle =
          showTitle
              + " "
              + Utils.getEpisodeNumber(
                  this,
                  upcomingEpisodes.getInt(NotificationQuery.SEASON),
                  upcomingEpisodes.getInt(NotificationQuery.NUMBER));
      contentText = getString(R.string.upcoming_show_detailed, airs, network);

      Intent notificationIntent = new Intent(context, EpisodesActivity.class);
      notificationIntent.putExtra(
          EpisodesActivity.InitBundle.EPISODE_TVDBID,
          upcomingEpisodes.getInt(NotificationQuery._ID));
      notificationIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime);
      contentIntent =
          PendingIntent.getActivity(context, REQUEST_CODE_SINGLE_EPISODE, notificationIntent, 0);
    } else if (count > 1) {
      // notify about multiple episodes
      tickerText = getString(R.string.upcoming_episodes);
      contentTitle = getString(R.string.upcoming_episodes_number, count);
      contentText = getString(R.string.upcoming_display);

      Intent notificationIntent = new Intent(context, UpcomingRecentActivity.class);
      notificationIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime);
      contentIntent =
          PendingIntent.getActivity(context, REQUEST_CODE_MULTIPLE_EPISODES, notificationIntent, 0);
    }

    final NotificationCompat.Builder nb = new NotificationCompat.Builder(context);

    if (AndroidUtils.isJellyBeanOrHigher()) {
      // JELLY BEAN and above

      if (count == 1) {
        // single episode
        upcomingEpisodes.moveToFirst();
        final String imagePath = upcomingEpisodes.getString(NotificationQuery.POSTER);
        nb.setLargeIcon(ImageProvider.getInstance(context).getImage(imagePath, true));

        final String episodeTitle = upcomingEpisodes.getString(NotificationQuery.TITLE);
        final String episodeSummary = upcomingEpisodes.getString(NotificationQuery.OVERVIEW);

        final SpannableStringBuilder bigText = new SpannableStringBuilder();
        bigText.append(episodeTitle);
        bigText.setSpan(new ForegroundColorSpan(Color.WHITE), 0, bigText.length(), 0);
        bigText.append("\n");
        bigText.append(episodeSummary);

        nb.setStyle(
            new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(contentText));

        // Action button to check in
        Intent checkInActionIntent = new Intent(context, QuickCheckInActivity.class);
        checkInActionIntent.putExtra(
            QuickCheckInActivity.InitBundle.EPISODE_TVDBID,
            upcomingEpisodes.getInt(NotificationQuery._ID));
        PendingIntent checkInIntent =
            PendingIntent.getActivity(context, REQUEST_CODE_ACTION_CHECKIN, checkInActionIntent, 0);
        nb.addAction(R.drawable.ic_action_checkin, getString(R.string.checkin), checkInIntent);
      } else {
        // multiple episodes
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

        // display at most the first five
        final int displayCount = Math.min(count, 5);
        for (int i = 0; i < displayCount; i++) {
          if (upcomingEpisodes.moveToPosition(i)) {
            // add show title, air time and network
            final SpannableStringBuilder lineText = new SpannableStringBuilder();
            lineText.append(upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE));
            lineText.setSpan(new ForegroundColorSpan(Color.WHITE), 0, lineText.length(), 0);
            lineText.append(" ");
            String airs =
                Utils.formatToTimeAndDay(
                    upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS), this)[0];
            String network = upcomingEpisodes.getString(NotificationQuery.NETWORK);
            lineText.append(getString(R.string.upcoming_show_detailed, airs, network));
            inboxStyle.addLine(lineText);
          }
        }

        // tell if we could not display all episodes
        if (count > 5) {
          inboxStyle.setSummaryText(getString(R.string.more, count - 5));
        }

        nb.setStyle(inboxStyle);
        nb.setContentInfo(String.valueOf(count));
      }
    } else {
      // ICS and below

      if (count == 1) {
        // single episode
        upcomingEpisodes.moveToFirst();
        final String posterPath = upcomingEpisodes.getString(NotificationQuery.POSTER);
        nb.setLargeIcon(ImageProvider.getInstance(context).getImage(posterPath, true));
      }
    }

    // If the string is empty, the user chose silent...
    if (ringtoneUri.length() != 0) {
      // ...otherwise set the specified ringtone
      nb.setSound(Uri.parse(ringtoneUri));
    }
    if (isVibrating) {
      nb.setVibrate(VIBRATION_PATTERN);
    }
    nb.setDefaults(Notification.DEFAULT_LIGHTS);
    nb.setWhen(System.currentTimeMillis());
    nb.setAutoCancel(true);
    nb.setTicker(tickerText);
    nb.setContentTitle(contentTitle);
    nb.setContentText(contentText);
    nb.setContentIntent(contentIntent);
    nb.setSmallIcon(R.drawable.ic_notification);
    nb.setPriority(NotificationCompat.PRIORITY_DEFAULT);

    Intent i = new Intent(this, NotificationService.class);
    i.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime);
    PendingIntent deleteIntent = PendingIntent.getService(this, 1, i, 0);
    nb.setDeleteIntent(deleteIntent);

    // build the notification
    Notification notification = nb.build();

    // use string resource id, always unique within app
    final NotificationManager nm =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(R.string.upcoming_show, notification);
  }