Exemplo n.º 1
0
  @Override
  public void onReceive(Context context, Intent i) {
    Log.d("alarm", "alarm ring! ring!");

    NotificationManager nm =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mCompatBuilder = new NotificationCompat.Builder(context);
    switch (i.getIntExtra("sound", 0)) {
      case 0:
        if ("ON".equals(SharedPreferenceManager.getInstance().getSound())) {
          mCompatBuilder.setDefaults(Notification.DEFAULT_SOUND);
        } else {
          mCompatBuilder.setDefaults(Notification.DEFAULT_LIGHTS);
        }
        break;
      case 1:
        if ("ON".equals(SharedPreferenceManager.getInstance().getVibration())) {
          mCompatBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        } else {
          mCompatBuilder.setDefaults(Notification.DEFAULT_LIGHTS);
        }
        break;
      case 2:
        mCompatBuilder.setDefaults(Notification.DEFAULT_LIGHTS);
        break;
    }
    mCompatBuilder.setSmallIcon(R.drawable.ic_launcher);
    mCompatBuilder.setTicker(i.getStringExtra("ticker"));
    mCompatBuilder.setContentTitle(i.getStringExtra("title"));
    mCompatBuilder.setContentText(i.getStringExtra("text"));
    mCompatBuilder.setAutoCancel(true);
    nm.notify(0, mCompatBuilder.build());
  }
  private void sendNotification(String msg) {
    Intent resultIntent = new Intent(this, DashBoardActivity.class);
    resultIntent.putExtra("msg", msg);
    PendingIntent resultPendingIntent =
        PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder mNotifyBuilder;
    NotificationManager mNotificationManager;

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mNotifyBuilder =
        new NotificationCompat.Builder(this)
            .setContentTitle("Alert")
            .setContentText("You've received new message.")
            .setSmallIcon(R.drawable.ic_launcher);
    // Set pending intent
    mNotifyBuilder.setContentIntent(resultPendingIntent);

    // Set Vibrate, Sound and Light
    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS;
    defaults = defaults | Notification.DEFAULT_VIBRATE;
    defaults = defaults | Notification.DEFAULT_SOUND;

    mNotifyBuilder.setDefaults(defaults);
    // Set the content for Notification
    mNotifyBuilder.setContentText("New message from Server");
    // Set autocancel
    mNotifyBuilder.setAutoCancel(true);
    // Post a notification
    mNotificationManager.notify(notifyID, mNotifyBuilder.build());
  }
  private Notification makeNotification(
      PendingIntent pendingIntent,
      String title,
      String content,
      String tickerText,
      int iconId,
      boolean ring,
      boolean vibrate) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder
        .setContentTitle(title)
        .setContentText(content)
        .setAutoCancel(true)
        .setContentIntent(pendingIntent)
        .setTicker(tickerText)
        .setSmallIcon(iconId);
    int defaults = Notification.DEFAULT_LIGHTS;
    if (vibrate) {
      defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (ring) {
      defaults |= Notification.DEFAULT_SOUND;
    }
    builder.setDefaults(defaults);

    return builder.build();
  }
  private void sendNotification(Article article) {
    try {
      Intent resultIntent = new Intent(this, ContentActivity.class);
      resultIntent.putExtra("name", article.name);
      resultIntent.putExtra("email", article.email);
      resultIntent.putExtra("id", article.id);
      resultIntent.putExtra("categoryId", article.category);
      resultIntent.putExtra("timestamp", article.timestamp);
      resultIntent.putExtra("title", article.title);

      PendingIntent resultPendingIntent =
          PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_ONE_SHOT);

      NotificationCompat.Builder mNotifyBuilder;
      NotificationManager mNotificationManager;

      Bitmap largeImage = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

      mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

      mNotifyBuilder =
          new NotificationCompat.Builder(this)
              .setCategory(NotificationCompat.CATEGORY_MESSAGE)
              .setPriority(NotificationCompat.PRIORITY_MAX)
              .setContentTitle("An article just got published")
              .setContentText("\"" + article.title + "\" by " + article.name)
              .setSmallIcon(R.mipmap.ic_launcher)
              .setLargeIcon(largeImage);
      mNotifyBuilder.setContentIntent(resultPendingIntent);

      int defaults = 0;
      defaults = defaults | Notification.DEFAULT_LIGHTS;
      defaults = defaults | Notification.DEFAULT_VIBRATE;
      defaults = defaults | Notification.DEFAULT_SOUND;

      mNotifyBuilder.setDefaults(defaults);
      mNotifyBuilder.setAutoCancel(true);
      mNotificationManager.notify(4321, mNotifyBuilder.build());

      SharedPreferences.Editor editor = sf.edit();
      editor.putBoolean(Constants.ReloadFeeds, true);
      editor.commit();

      Intent intent = new Intent("notification_received");
      intent.putExtra("name", article.name);
      intent.putExtra("email", article.email);
      intent.putExtra("id", article.id);
      intent.putExtra("categoryId", article.category);
      intent.putExtra("timestamp", article.timestamp);
      intent.putExtra("title", article.title);
      LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

    } catch (Exception ignored) {

    }
  }
Exemplo n.º 5
0
  private static Notification buildNotification(
      Context context,
      boolean playSound,
      boolean useLights,
      int icon,
      String message,
      NotificationCompat.InboxStyle bigTextStyle) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Resources res = context.getResources();
    String title = res.getString(R.string.app_name);

    int defaults = 0;

    // Build the compatible notification
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context).setContentTitle(title).setAutoCancel(true);
    if (useLights) builder.setLights(0xffff6000, 500, 1000);
    builder.setSmallIcon(icon);

    if (playSound) {
      String ringtone = prefs.getString("notifications_new_message_ringtone", null);
      Uri ringtoneUri = null;
      if (ringtone == null) {
        ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      } else {
        ringtoneUri = Uri.parse(ringtone);
      }
      builder.setSound(ringtoneUri);

      // Vibrate only if we are playing a sound
      if (prefs.getBoolean("notifications_new_message_vibrate", true)) {
        defaults |= Notification.DEFAULT_VIBRATE;
      }
    }

    builder.setContentText(message);
    if (bigTextStyle != null) {
      builder.setStyle(bigTextStyle);
    }
    builder.setDefaults(defaults);

    // Creates an explicit intent for ChatActivity
    Intent resultIntent = new Intent(context, ChatActivity.class);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    resultIntent.setAction("android.intent.action.MAIN");

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

    return builder.build();
  }
Exemplo n.º 6
0
  /**
   * @param ID データベースのID
   * @param title Notificationで表示されるタイトル
   * @param subTitle Notificationで表示されるサブタイトル
   * @param message Notificationが生成された時に表示されるステータスメッセージ
   * @param color メモ画面での色
   * @param content メモ画面の中身
   * @param photoPath カメラ撮影時の画像ファイルパス
   * @param drawingPath 手書きの画像ファイルパス
   * @param voicePath 音声ファイルパス
   */
  private void setToDoDetailNotification(
      int ID,
      String title,
      String subTitle,
      String message,
      int color,
      String content,
      String photoPath,
      String drawingPath,
      String voicePath) {
    // Intentの作成
    // ※ 要変更:現在はスタブクラスにインテントを渡しているが、これを本来のMemo画面クラスに渡す
    Intent intent = new Intent(SetToDoNotification.this, StubMemoActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // サービスからインテントを使用するためにフラグを設定

    // Memo画面に必要な情報をインテントに格納する
    intent.putExtra("Color", color);
    intent.putExtra("Content", content);
    intent.putExtra("PhotoPath", photoPath);
    intent.putExtra("DrawingPath", drawingPath);
    intent.putExtra("VoicePath", voicePath);
    PendingIntent contentIntent =
        PendingIntent.getActivity(
            SetToDoNotification.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // NotificationBuilderを作成
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
    // Intentを埋め込む
    builder.setContentIntent(contentIntent);
    // ステータスバーに表示されるテキスト
    builder.setTicker(message);
    // アイコン
    builder.setSmallIcon(android.R.drawable.ic_menu_today);
    // Notificationを開いた時に表示されるタイトル
    builder.setContentTitle(title);
    // Notificationを開いた時に表示されるサブタイトル
    builder.setContentText(subTitle);
    // Notificationを開いた時に表示されるアイコン
    // builder.setLargeIcon(largeIcon);
    // 通知するタイミング
    builder.setWhen(System.currentTimeMillis());
    // 通知時の音・ライト
    builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS);
    // タップするとキャンセル(消える)
    builder.setAutoCancel(true);

    // NotificationManagerを取得
    NotificationManager manager =
        (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
    // Notificationを作成して通知
    manager.notify(ID, builder.build());
  }
 /**
  * Generate a notification
  *
  * @param pendingIntent pending intent
  * @param title title
  * @param message message
  * @return the notification
  */
 private Notification buildNotification(
     PendingIntent pendingIntent, String title, String message) {
   NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
   notif.setContentIntent(pendingIntent);
   notif.setSmallIcon(R.drawable.ri_notif_file_transfer_icon);
   notif.setWhen(System.currentTimeMillis());
   notif.setAutoCancel(true);
   notif.setOnlyAlertOnce(true);
   notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
   notif.setDefaults(Notification.DEFAULT_VIBRATE);
   notif.setContentTitle(title);
   notif.setContentText(message);
   return notif.build();
 }
Exemplo n.º 8
0
 private void showNotification(Context context, int id, String title, String content) {
   PendingIntent contentIntent =
       PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
   NotificationCompat.Builder mBuilder =
       new NotificationCompat.Builder(context)
           .setSmallIcon(R.drawable.selectedstar)
           .setContentTitle(title)
           .setContentText(content);
   mBuilder.setContentIntent(contentIntent);
   mBuilder.setDefaults(Notification.DEFAULT_SOUND);
   mBuilder.setAutoCancel(true);
   NotificationManager mNotificationManager =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   mNotificationManager.notify(id, mBuilder.build());
 }
Exemplo n.º 9
0
  @Override
  public void onReceive(Context context, Intent intent) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(R.drawable.registration_notification);
    builder.setContentTitle(intent.getStringExtra(RegistrationService.NOTIFICATION_TITLE));
    builder.setContentText(intent.getStringExtra(RegistrationService.NOTIFICATION_TEXT));
    builder.setContentIntent(
        PendingIntent.getActivity(context, 0, new Intent(context, DialerActivity.class), 0));
    builder.setWhen(System.currentTimeMillis());
    builder.setDefaults(Notification.DEFAULT_VIBRATE);
    builder.setAutoCancel(true);

    Notification notification = builder.build();
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
        .notify(31337, notification);
  }
 private void sendNotification(String text) {
   NotificationManager mNotificationManager =
       (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
   NotificationCompat.Builder notification = new NotificationCompat.Builder(ctx);
   notification.setContentTitle(ctx.getString(R.string.app_name));
   notification.setContentText(text);
   notification.setAutoCancel(true);
   if (Common.isVibrate()) {
     notification.setDefaults(Notification.DEFAULT_VIBRATE);
   }
   notification.setSmallIcon(R.drawable.ic_launcher);
   if (!TextUtils.isEmpty(Common.getRingtone())) {
     notification.setSound(Uri.parse(Common.getRingtone()));
   }
   mNotificationManager.notify(0, notification.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);
     }
   }
 }
  // creating notification function
  public void createNotification(Context context, String msg, String msgText, String msgAlert) {

    int id = (int) System.currentTimeMillis();
    Intent i = new Intent(context, StopAlarm.class);
    i.putExtra("passuser", user);
    i.putExtra("inputCode", inputCode);

    i.putExtra(
        "reminderTitle",
        titleOfReminder); // store the title of the reminder which need to pass to the next activity
    i.putExtra("reminderStartTime", startTimeOfReminder); // store the start time of the reminder
    i.putExtra("remminderStartDate", startDateOfReminder); // store the start date of the reminder
    i.putExtra("repeat", repeatReminder); // store if user want this alarm to repeat the schedule.

    i.putExtra("selectedHour", selectedHour);
    i.putExtra("selectedMinute", selectedMinute);
    i.putExtra("selectedDay", selectedDay);
    i.putExtra("selectedMonth", selectedMonth);
    i.putExtra("selectedYear", selectedYear);

    i.putExtra("notirequestcode", notiRequestCode);

    notificIntent = PendingIntent.getActivity(context, id, i, 0);
    // using notification builder to set up the notification layout and configuration
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_alarm_24dp)
            .setContentTitle(msg)
            .setTicker(msgAlert)
            .setContentText(msgText);
    mBuilder.setContentIntent(notificIntent);
    mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE);
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    mBuilder.setSound(
        uri); // this is to set the sound so that when notification is received, there will also
              // have default sound being released
    mBuilder.setAutoCancel(true);

    mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(
        1, mBuilder.build()); // to set to receive notification for each alarm change the int here.
  }
  private void addSessionInvitationNotification(Intent intent, ContactId contact) {
    /* Create pending intent */
    Intent invitation = new Intent(intent);
    String title;
    if (mMultimediaMessagingSession) {
      invitation.setClass(this, MessagingSessionView.class);
      title = getString(R.string.title_recv_messaging_session);
    } else {
      invitation.setClass(this, StreamingSessionView.class);
      title = getString(R.string.title_recv_streaming_session);
    }
    invitation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    /*
     * If the PendingIntent has the same operation, action, data, categories, components, and
     * flags it will be replaced. Invitation should be notified individually so we use a random
     * generator to provide a unique request code and reuse it for the notification.
     */
    int uniqueId = Utils.getUniqueIdForPendingIntent();
    PendingIntent contentIntent =
        PendingIntent.getActivity(this, uniqueId, invitation, PendingIntent.FLAG_ONE_SHOT);

    String displayName = RcsContactUtil.getInstance(this).getDisplayName(contact);

    /* Create notification */
    NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
    notif.setContentIntent(contentIntent);
    notif.setSmallIcon(R.drawable.ri_notif_mm_session_icon);
    notif.setWhen(System.currentTimeMillis());
    notif.setAutoCancel(true);
    notif.setOnlyAlertOnce(true);
    notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notif.setDefaults(Notification.DEFAULT_VIBRATE);
    notif.setContentTitle(title);
    notif.setContentText(getString(R.string.label_from_args, displayName));

    /* Send notification */
    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(uniqueId, notif.build());
  }
  /**
   * 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());
  }
  private void newMessageNotification(String text, String senderEmail) {
    NotificationManager mNotificationManager =
        (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder notification = new NotificationCompat.Builder(ctx);
    notification.setContentTitle(ctx.getString(R.string.app_name) + "-" + text);
    notification.setContentText(senderEmail);
    notification.setAutoCancel(true);
    if (Common.isVibrate()) {
      notification.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    notification.setSmallIcon(R.drawable.ic_launcher);
    if (!TextUtils.isEmpty(Common.getRingtone())) {
      notification.setSound(Uri.parse(Common.getRingtone()));
    }

    Intent intent = new Intent(ctx, ChatActivity.class);
    intent.putExtra(Common.IS_NOTIF, true);
    intent.putExtra(Common.PROFILE_NAME, senderEmail);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pi = PendingIntent.getActivity(ctx, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
    notification.setContentIntent(pi);

    mNotificationManager.notify(1, notification.build());
  }
Exemplo n.º 16
0
  /**
   * Shows the notification with repost and discard options. Multiple Place-its listed as separate
   * notifications.
   */
  public static void notify(final Context context, final int pID) {
    final Resources res = context.getResources();

    PlaceIt placeIt = PlaceItList.find(pID);
    final String title = placeIt.getTitle();
    // address for Categorical, Location cordinate for regular
    String address = placeIt.getDescription();
    if (placeIt.getClass() == CategoricalPlaceIt.class) {
      address = ((CategoricalPlaceIt) placeIt).getAddress();
    } else {
      address =
          ""
              + ((LocationPlaceIt) placeIt).getLocation().getLatitude()
              + ((LocationPlaceIt) placeIt).getLocation().getLongitude();
    }

    final String fullTitle = res.getString(R.string.place_it_notification_title_template, title);
    final String fullAddress = res.getString(R.string.place_it_notification_text_template, address);

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

    // Set appropriate defaults for the notification light, sound,
    // and vibration.
    notification.setDefaults(Notification.DEFAULT_ALL);

    // required values
    notification.setSmallIcon(R.drawable.ic_launcher);
    notification.setContentTitle(fullTitle);
    notification.setContentText(fullAddress);

    // Set preview information for this notification.
    notification.setTicker(title);

    // On click action go to DescriptionActivity
    Intent descriptionIntent =
        new Intent(context, DescriptionActivity.class).putExtra(MainActivity.PLACEIT_ID, pID);
    notification.setContentIntent(
        PendingIntent.getActivity(
            context, pID, descriptionIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Repost action
    Intent repostIntent =
        new Intent(context, PlaceItNotification.class)
            .putExtra(BUTTON_TAG, R.string.notification_repost)
            .putExtra(MainActivity.PLACEIT_ID, pID);
    notification.addAction(
        R.drawable.ic_stat_repost,
        res.getString(R.string.notification_repost),
        PendingIntent.getBroadcast(context, 0, repostIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Discard action
    Intent discardIntent =
        new Intent(context, PlaceItNotification.class)
            .putExtra(BUTTON_TAG, R.string.notification_discard)
            .putExtra(MainActivity.PLACEIT_ID, pID);

    notification.addAction(
        R.drawable.ic_stat_discard,
        res.getString(R.string.notification_discard),
        PendingIntent.getBroadcast(context, 0, discardIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Automatically dismiss the notification when it is touched.
    notification.setAutoCancel(true);

    notify(context, notification.build(), pID);
  }
Exemplo n.º 17
0
  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);
  }
  private void sendNotification(String msg, String webId, Bitmap bitmap) {

    final PostsDataSource postsDataSource = new PostsDataSource(this);
    final String webId2 = webId;
    final String msg2 = msg;
    final Bitmap bitmap1 = bitmap;
    postsDataSource.open();

    if (postsDataSource.countRow(
            DB.POST_TABLE,
            DB.POST_COLUMNS,
            DB.POST_COLUMN_WEB_ID + " = ? ",
            new String[] {webId},
            null)
        == 0) {
      new WebClient(
          URL.buildUrl(WebUrl.POST_URL, "20", webId, null, null, null, null),
          new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
              List<Post> postList;
              postList = WebJSONParser.postParseFeed(response);
              postsDataSource.insertPosts(postList);

              Post post =
                  postsDataSource.getPost(
                      DB.POST_COLUMN_WEB_ID + " = ? ", new String[] {webId2}, null);

              Intent intent = new Intent(getApplicationContext(), DetailActivity.class);
              intent.putExtra("id", Long.toString(post.getPostId()));
              intent.putExtra("type", post.getType());
              intent.putExtra("categoryId", "no");
              intent.putExtra("webId", webId2);

              // PendingIntent resultPendingIntent =
              // PendingIntent.getActivity(getApplicationContext(), 0, intent,
              // PendingIntent.FLAG_ONE_SHOT);
              NotificationCompat.Builder mNotifyBuilder;
              NotificationManager mNotificationManager;

              mNotificationManager =
                  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

              mNotifyBuilder =
                  new NotificationCompat.Builder(getApplicationContext())
                      .setContentTitle(msg2)
                      .setTicker(msg2)
                      .setSmallIcon(R.drawable.ic_launcher);

              if (bitmap1 != null) {
                mNotifyBuilder.setLargeIcon(bitmap1);
              }

              if (post.getContent() != null) {
                mNotifyBuilder.setContentText(Html.fromHtml(post.getContent()));
              }

              // Creates an explicit intent for an Activity in your app
              //  Intent resultIntent = new Intent(this, testActivity.class);

              // The stack builder object will contain an artificial back stack
              // for
              // the
              // started Activity.
              // This ensures that navigating backward from the Activity leads out
              // of
              // your application to the Home screen.
              TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());

              // Adds the back stack for the Intent (but not the Intent itself)
              stackBuilder.addParentStack(HomeActivity.class);

              // Adds the Intent that starts the Activity to the top of the stack
              stackBuilder.addNextIntent(intent);
              PendingIntent resultPendingIntent =
                  stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
              mNotifyBuilder.setContentIntent(resultPendingIntent);

              //   mNotifyBuilder.setContentIntent(resultPendingIntent);

              // Set Vibrate, Sound and Light
              int defaults = 0;
              defaults = defaults | Notification.DEFAULT_LIGHTS;
              defaults = defaults | Notification.DEFAULT_VIBRATE;
              defaults = defaults | Notification.DEFAULT_SOUND;

              mNotifyBuilder.setDefaults(defaults);
              // Set the content for Notification
              mNotifyBuilder.setContentText(msg2);
              // Set autocancel
              mNotifyBuilder.setAutoCancel(true);
              mNotifyBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
              // Post a notification
              mNotificationManager.notify(notifyID, mNotifyBuilder.build());
            }
          },
          new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {}
          },
          Request.Priority.HIGH);

      return;
    } else {

      Post post =
          postsDataSource.getPost(DB.POST_COLUMN_WEB_ID + " = ? ", new String[] {webId}, null);

      Intent intent = new Intent(this, DetailActivity.class);
      intent.putExtra("id", Long.toString(post.getPostId()));
      intent.putExtra("type", post.getType());
      intent.putExtra("categoryId", "no");
      intent.putExtra("webId", webId);

      // PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, intent,
      // PendingIntent.FLAG_ONE_SHOT);
      NotificationCompat.Builder mNotifyBuilder;
      NotificationManager mNotificationManager;

      mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

      mNotifyBuilder =
          new NotificationCompat.Builder(this)
              .setContentTitle(msg)
              .setTicker(msg)
              .setSmallIcon(R.drawable.ic_launcher);

      if (bitmap1 != null) {
        mNotifyBuilder.setLargeIcon(bitmap1);
      }

      if (post.getContent() != null) {
        mNotifyBuilder.setContentText(Html.fromHtml(post.getContent()));
      }

      // Creates an explicit intent for an Activity in your app
      //  Intent resultIntent = new Intent(this, testActivity.class);

      // The stack builder object will contain an artificial back stack
      // for
      // the
      // started Activity.
      // This ensures that navigating backward from the Activity leads out
      // of
      // your application to the Home screen.
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

      // Adds the back stack for the Intent (but not the Intent itself)
      stackBuilder.addParentStack(HomeActivity.class);

      // Adds the Intent that starts the Activity to the top of the stack
      stackBuilder.addNextIntent(intent);
      PendingIntent resultPendingIntent =
          stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
      mNotifyBuilder.setContentIntent(resultPendingIntent);

      //   mNotifyBuilder.setContentIntent(resultPendingIntent);

      // Set Vibrate, Sound and Light
      int defaults = 0;
      defaults = defaults | Notification.DEFAULT_LIGHTS;
      defaults = defaults | Notification.DEFAULT_VIBRATE;
      defaults = defaults | Notification.DEFAULT_SOUND;

      mNotifyBuilder.setDefaults(defaults);
      //  mNotifyBuilder.setContentText(msg);
      mNotifyBuilder.setAutoCancel(true);
      mNotifyBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
      mNotificationManager.notify(notifyID, mNotifyBuilder.build());
    }
  }
Exemplo n.º 19
0
  public void postNotification(int id) {

    if (notificationItems.size() == 0) {
      return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setContentTitle(notificationTitle);
    mBuilder.setSmallIcon(R.drawable.ic_stat_icon);
    mBuilder.setLargeIcon(
        BitmapFactory.decodeResource(
            context.getResources(), R.drawable.ic_action_notification_dark));

    if (notificationItems.size() > 1) {
      // inbox style
      NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle();

      try {
        inbox.setBigContentTitle(notificationTitle);
      } catch (Exception e) {

      }

      if (notificationItems.size() <= 5) {
        for (String s : notificationItems) {
          inbox.addLine(Html.fromHtml(s));
        }
      } else {
        for (int i = 0; i < 5; i++) {
          inbox.addLine(Html.fromHtml(notificationItems.get(i)));
        }

        int extra = notificationItems.size() - 5;
        if (extra > 1) {
          inbox.setSummaryText("+" + extra + " " + context.getString(R.string.items));
        } else {
          inbox.setSummaryText("+" + extra + " " + context.getString(R.string.item));
        }
      }

      mBuilder.setStyle(inbox);
      mBuilder.setContentText(notificationItems.size() + " " + context.getString(R.string.items));
    } else {
      // big text style
      NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
      bigText.bigText(Html.fromHtml(notificationItems.get(0)));
      bigText.setBigContentTitle(notificationTitle);

      mBuilder.setStyle(bigText);
      mBuilder.setContentText(Html.fromHtml(notificationItems.get(0)));
    }

    if (!useSecondAccount) {
      mBuilder.setContentIntent(
          PendingIntent.getActivity(context, 0, new Intent(context, RedirectToActivity.class), 0));
    }

    if (settings.vibrate) {
      mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
      try {
        mBuilder.setSound(Uri.parse(settings.ringtone));
      } catch (Exception e) {
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
      }
    }

    if (settings.led) {
      mBuilder.setLights(0xFFFFFF, 1000, 1000);
    }

    if (settings.wakeScreen) {
      PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
      final PowerManager.WakeLock wakeLock =
          pm.newWakeLock(
              (PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                  | PowerManager.FULL_WAKE_LOCK
                  | PowerManager.ACQUIRE_CAUSES_WAKEUP),
              "TAG");
      wakeLock.acquire(5000);
    }

    // Pebble notification
    if (sharedPrefs.getBoolean("pebble_notification", false)) {
      NotificationUtils.sendAlertToPebble(context, notificationTitle, notificationItems.get(0));
    }

    // Light Flow notification
    NotificationUtils.sendToLightFlow(context, notificationTitle, notificationItems.get(0));

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(id, mBuilder.build());
  }
  private void showNotification(
      Context context,
      int notificationId,
      int smallIconId,
      String title,
      String contentText,
      String bigTitle,
      String bigContentText,
      String summaryText,
      String ticker,
      Intent intent) {
    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSound(soundUri);

    if (smallIconId == 0) {
      builder.setSmallIcon(R.mipmap.ic_launcher);
    } else {
      builder.setSmallIcon(smallIconId);
    }
    builder.setWhen(System.currentTimeMillis());
    // builder.setNumber(10);

    if (!StringUtils.isEmptyString(ticker)) {
      builder.setTicker(ticker);
    }

    if (StringUtils.isEmptyString(title)) {
      builder.setContentTitle(PackageUtils.getApplicationName(context));
    } else {
      builder.setContentTitle(title);
    }
    builder.setContentText(contentText);
    builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    builder.setAutoCancel(true);

    // big title and text
    if (!StringUtils.isEmptyString(bigTitle) && !StringUtils.isEmptyString(bigContentText)) {
      NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder);
      if (!StringUtils.isEmptyString(summaryText)) {
        style.setSummaryText(summaryText);
      }
      style.setBigContentTitle(bigTitle);
      style.bigText(bigContentText);

      builder.setStyle(style);
    }

    if (intent != null) {
      intent.setFlags(
          intent.FLAG_ACTIVITY_CLEAR_TOP
              | Intent.FLAG_ACTIVITY_SINGLE_TOP
              | Intent.FLAG_ACTIVITY_CLEAR_TASK
              | Intent.FLAG_ACTIVITY_NEW_TASK);
      PendingIntent pendingIntent =
          PendingIntent.getActivity(
              context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      builder.setContentIntent(pendingIntent);
    }

    notificationManager.notify(notificationId, builder.build());
  }
  public void createNotification(Context context, Bundle extras) {
    int notId = 0;

    try {
      notId = Integer.parseInt(extras.getString("notId"));
    } catch (NumberFormatException e) {
      Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
    } catch (Exception e) {
      Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
    }
    if (notId == 0) {
      // no notId passed, so assume we want to show all notifications, so make it a random number
      notId = new Random().nextInt(100000);
      Log.d(TAG, "Generated random notId: " + notId);
    } else {
      Log.d(TAG, "Received notId: " + notId);
    }

    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(context);

    Intent notificationIntent = new Intent(context, PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, notId, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    int defaults = Notification.DEFAULT_ALL;

    if (extras.getString("defaults") != null) {
      try {
        defaults = Integer.parseInt(extras.getString("defaults"));
      } catch (NumberFormatException ignore) {
      }
    }

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(defaults)
            .setSmallIcon(getSmallIcon(context, extras))
            .setWhen(System.currentTimeMillis())
            .setContentTitle(extras.getString("title"))
            .setTicker(extras.getString("title"))
            .setContentIntent(contentIntent)
            .setColor(getColor(extras))
            .setAutoCancel(true);

    String message = extras.getString("message");
    if (message != null) {
      mBuilder.setContentText(message);
    } else {
      mBuilder.setContentText("<missing message content>");
    }

    String msgcnt = extras.getString("msgcnt");
    if (msgcnt != null) {
      mBuilder.setNumber(Integer.parseInt(msgcnt));
    }

    String soundName = extras.getString("sound");
    if (soundName != null) {
      Resources r = context.getResources();
      int resourceId = r.getIdentifier(soundName, "raw", context.getPackageName());
      Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resourceId);
      mBuilder.setSound(soundUri);
      defaults &= ~Notification.DEFAULT_SOUND;
      mBuilder.setDefaults(defaults);
    }

    final Notification notification = mBuilder.build();
    final int largeIcon = getLargeIcon(context, extras);
    if (largeIcon > -1) {
      notification.contentView.setImageViewResource(android.R.id.icon, largeIcon);
    }

    mNotificationManager.notify(appName, notId, notification);
  }
Exemplo n.º 22
0
 @Override
 public Builder setDefaults(int defaults) {
   super.setDefaults(defaults);
   return this;
 }
Exemplo n.º 23
0
 /**
  * 设置一个提醒动作
  *
  * @param builder
  * @return
  */
 private NotificationCompat.Builder setAlertAction(NotificationCompat.Builder builder) {
   // 设置默认铃声和振动
   builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
   return builder;
 }
  public void notify(
      String notificationId,
      String apiKey,
      String title,
      String message,
      String uri,
      String imageUrl) {
    Log.d(LOGTAG, "notify()...");

    Log.d(LOGTAG, "notificationId=" + notificationId);
    Log.d(LOGTAG, "notificationApiKey=" + apiKey);
    Log.d(LOGTAG, "notificationTitle=" + title);
    Log.d(LOGTAG, "notificationMessage=" + message);
    Log.d(LOGTAG, "notificationUri=" + uri);

    if (isNotificationEnabled()) {
      // Show the toast
      if (isNotificationToastEnabled()) {
        Toast.makeText(context, message, Toast.LENGTH_LONG).show();
      }
      mBuilder
          .setWhen(System.currentTimeMillis()) // 通知产生的时间,会在通知信息里显示
          .setPriority(Notification.PRIORITY_DEFAULT) // 设置该通知优先级
          //				.setAutoCancel(true)//设置这个标志当用户单击面板就可以让通知将自动取消
          .setOngoing(
              false) // ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接)
          .setDefaults(
              Notification
                  .DEFAULT_VIBRATE) // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
          // Notification.DEFAULT_ALL  Notification.DEFAULT_SOUND 添加声音 // requires VIBRATE
          // permission
          .setSmallIcon(getNotificationIcon());

      mBuilder
          .setAutoCancel(true) // 点击后让通知将消失
          .setContentTitle(title)
          .setContentText(message)
          .setTicker(message);
      // Notification
      if (isNotificationSoundEnabled()) {
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
      }
      if (isNotificationVibrateEnabled()) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
      }
      mBuilder.setOnlyAlertOnce(true);

      //            Intent intent;
      //            if (uri != null
      //                    && uri.length() > 0
      //                    && (uri.startsWith("http:") || uri.startsWith("https:")
      //                            || uri.startsWith("tel:") || uri.startsWith("geo:"))) {
      //                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
      //            } else {
      //                String callbackActivityPackageName = sharedPrefs.getString(
      //                        Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, "");
      //                String callbackActivityClassName = sharedPrefs.getString(
      //                        Constants.CALLBACK_ACTIVITY_CLASS_NAME, "");
      //                intent = new Intent().setClassName(callbackActivityPackageName,
      //                        callbackActivityClassName);
      //                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      //                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
      //            }

      Intent intent = new Intent(context, NotificationDetailsActivity.class);
      intent.putExtra(Constants.NOTIFICATION_ID, notificationId);
      intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
      intent.putExtra(Constants.NOTIFICATION_TITLE, title);
      intent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
      intent.putExtra(Constants.NOTIFICATION_URI, uri);
      intent.putExtra(Constants.NOTIFICATION_IMAGE_URL, imageUrl);

      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
      intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
      intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

      PendingIntent contentIntent =
          PendingIntent.getActivity(
              context, random.nextInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT);

      mBuilder.setContentIntent(contentIntent);
      notificationManager.notify(random.nextInt(), mBuilder.build());

    } else {
      Log.w(LOGTAG, "Notificaitons disabled.");
    }
  }