@Override
  public void onReceive(Context context, Intent bootIntent) {
    // Check if enabled
    if (!Utils.isXposedEnabled()) {
      // Create Xposed installer intent
      Intent xInstallerIntent =
          context.getPackageManager().getLaunchIntentForPackage("de.robv.android.xposed.installer");
      if (xInstallerIntent != null) xInstallerIntent.putExtra("opentab", 1);

      PendingIntent pi =
          (xInstallerIntent == null
              ? null
              : PendingIntent.getActivity(
                  context, 0, xInstallerIntent, PendingIntent.FLAG_UPDATE_CURRENT));

      // Build notification
      NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
      notificationBuilder.setSmallIcon(R.drawable.ic_launcher);
      notificationBuilder.setContentTitle(context.getString(R.string.app_name));
      notificationBuilder.setContentText("PeerBlock For Android is not enabled in XPosed");
      notificationBuilder.setWhen(System.currentTimeMillis());
      notificationBuilder.setAutoCancel(true);
      if (pi != null) notificationBuilder.setContentIntent(pi);
      Notification notification = notificationBuilder.build();

      // Display notification
      NotificationManager notificationManager =
          (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      notificationManager.notify(0, notification);
    }
  }
  public static NotificationCompat.Builder getBaseBuilder(Context ctx, boolean setAutoCancel) {
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(ctx);
    notifBuilder.setSound(defaultSoundUri);
    notifBuilder.setAutoCancel(setAutoCancel);
    notifBuilder.setSmallIcon(R.drawable.ic_notification);

    // Notification styles changed since Lollipop
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      int color;
      // We have to check the M version for the deprecation of the method getColor()
      if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        color = ctx.getResources().getColor(R.color.highlight_light);
      } else {
        color = ctx.getResources().getColor(R.color.highlight_light);
      }
      notifBuilder.setColor(color);
    } else {
      // in older versions, we show the App logo
      notifBuilder.setLargeIcon(
          BitmapFactory.decodeResource(ctx.getResources(), MobileLearning.APP_LOGO));
    }

    return notifBuilder;
  }
  @Override
  public Notification createNotification(String title, String content, int icon) {

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

    notificationBuilder.setContentTitle(title);
    notificationBuilder.setContentText(content);

    notificationBuilder.setSmallIcon(icon);

    notificationBuilder.setAutoCancel(true);

    Intent resultIntent = NotificationDetailsActivity.getStartIntent(context, title, content);

    // 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(context);

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

    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.setContentIntent(resultPendingIntent);

    return notificationBuilder.build();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent i = new Intent(getIntent());
    nome = i.getIntExtra("nome", nome);
    foto = i.getIntExtra("foto", foto);
    id = UUID.fromString(i.getStringExtra("id"));
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle(getString(R.string.novo_evento));
    builder.setContentText(getString(nome));
    builder.setTicker(getString(R.string.notificacao_evento));
    builder.setSmallIcon(foto);

    //	TODO colocar rodar mesmo com app fechado
    Intent resultIntent = new Intent(this, EventoPagerActivity.class);
    resultIntent.putExtra(EventoFragment.EXTRA_EVENTO_ID, id);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
    builder.setContentIntent(resultPendingIntent);
    builder.setAutoCancel(true);
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(idNotificacao, builder.build());

    finish();
  }
  private void doNotify(
      Intent i,
      String contentTitle,
      List<Message> messages,
      int notificationCode,
      boolean withSound) {
    PendingIntent contentIntent =
        PendingIntent.getActivity(mContext, notificationCode, i, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(contentTitle)
            .setTicker(messages.get(0).getContent())
            .setContentText(messages.get(0).getContent());

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    String[] lastMessages = new String[Math.min(messages.size(), MAX_MESSAGES_PER_GROUP)];
    inboxStyle.setBigContentTitle(contentTitle);
    for (int j = 0; j < lastMessages.length; j++) {
      inboxStyle.addLine(messages.get(j).getContent());
    }
    builder.setStyle(inboxStyle);
    builder.setNumber(messages.size());
    builder.setContentIntent(contentIntent);
    builder.setAutoCancel(true);

    mNotificationManager.notify(notificationCode, builder.build());

    if (withSound) {
      mSoundEffectsPool.play(newMessageSoundId, 1.0f, 1.0f, 0, 0, 1);
    }
  }
  @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());
  }
  @Override
  public void vshow(
      final Context context,
      final String message,
      final String tickerText,
      final int id,
      PendingIntent contentIntent) {

    /*
     * If contentIntent is NULL, create valid contentIntent
     */
    if (contentIntent == null)
      contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setTicker(tickerText);
    builder.setWhen(System.currentTimeMillis());
    builder.setSmallIcon(R.drawable.icon);
    builder.setContentTitle(context.getText(R.string.app_name));
    builder.setContentIntent(contentIntent);
    builder.setContentText(message);
    builder.setAutoCancel(true);

    // unique ID
    notify(context, id, VSHOW_TAG, builder.build());
  }
  public void launchNotification(Context context, Events event) throws Exception {
    NotificationManager nManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Log.e("Notification", "Notification up");

    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_event_white_36dp)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(
                context.getString(R.string.notification1)
                    + " "
                    + event.getTitle()
                    + context.getString(R.string.notification2));

    Intent i = new Intent(context, EventFragment.class);
    i.putExtra("image", event.getImage());
    i.putExtra("title", event.getTitle());
    i.putExtra("description", event.getDescription());
    i.putExtra("date", event.getDate());
    i.putExtra("price", event.getPrice());
    i.putExtra("time", event.getTime());
    i.putExtra("notification", 0);

    PendingIntent contentIntent =
        PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationBuilder.setContentIntent(contentIntent);
    notificationBuilder.setAutoCancel(true);

    nManager.notify(123, notificationBuilder.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 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) {

    }
  }
  public void startNotification() {

    builder.setSmallIcon(R.drawable.ic_stat_name);
    builder.setContentIntent(pendingIntent);
    builder.setAutoCancel(false);
    builder.setOngoing(true);
    builder.setContentTitle("Job Timer");
    builder.setContentText("00:00:00");
    notificationManager.notify(NOTIFICATION_ID, builder.build());
  }
  /**
   * @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());
  }
Exemple #13
0
 public UploadImage(AppCompatActivity activity, String imageUri) {
   mActivity = activity;
   mImageUri = imageUri;
   mNotifyManager = (NotificationManager) mActivity.getSystemService(Context.NOTIFICATION_SERVICE);
   mBuilder = new NotificationCompat.Builder(mActivity);
   mBuilder
       .setContentTitle("Posting The Issue...")
       .setContentText("0%")
       .setSmallIcon(R.drawable.bullhorn_white);
   mBuilder.setAutoCancel(false);
   mBuilder.setOngoing(true);
   mBuilder.setProgress(100, 0, false);
   mNotifyManager.notify(id, mBuilder.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();
 }
  /**
   * 设置一个跳转动作 当点击Notification时候,跳转的Activity
   *
   * @param builder
   * @return
   */
  private NotificationCompat.Builder setForwardAction(NotificationCompat.Builder builder) {
    // 设置跳转Activity的Intent
    Intent intent = new Intent(this, NotificationDemo02.class);
    // 设置跳转Activity的属性,当跳转到Activity的时候,新启动这个Activity
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent notificationIntent =
        PendingIntent.getActivity(this, 1000, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    // 设置通知跳转
    builder.setContentIntent(notificationIntent);

    // 设置点击之后,通知取消,这个必须与跳转动作配合使用,如果只是设置了取消,但是没有跳转,无效
    builder.setAutoCancel(true);
    return builder;
  }
 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());
 }
    private void notify(String text, boolean ongoing) {
      NotificationCompat.Builder notificationBuilder =
          new NotificationCompat.Builder(ActivityMain.this);
      notificationBuilder.setSmallIcon(R.drawable.ic_launcher);
      notificationBuilder.setContentTitle(getString(R.string.menu_import));
      notificationBuilder.setContentText(text);
      notificationBuilder.setWhen(System.currentTimeMillis());
      if (ongoing) notificationBuilder.setOngoing(true);
      else notificationBuilder.setAutoCancel(true);
      Notification notification = notificationBuilder.build();

      NotificationManager notificationManager =
          (NotificationManager) ActivityMain.this.getSystemService(Context.NOTIFICATION_SERVICE);
      notificationManager.notify(NOTIFY_ID, notification);
    }
  @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);
  }
  public void show() {
    builder.setContentTitle(title());
    builder.setContentText(contentText());
    builder.setSmallIcon(smallIcon());
    builder.setTicker(contentText());
    builder.setAutoCancel(true);

    NotificationManager manager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    //        Notification notification = builder.build();
    //        notification.flags = Notification.FLAG_AUTO_CANCEL;
    //        notification.defaults = Notification.DEFAULT_ALL;

    manager.notify(id, builder.build());
  }
 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());
 }
 /**
  * this is to display the limit excess message to user as notification
  *
  * @param message
  */
 public void displayMessage(String message) {
   // TODO Auto-generated method stub
   Log.i("Testing", "In display function");
   NotificationCompat.Builder builder =
       new NotificationCompat.Builder(this)
           .setSmallIcon(R.drawable.ic_launcher)
           .setContentTitle("Month shopping limit")
           .setContentText(message);
   Intent notificationIntent = new Intent(this, StartActivity.class);
   PendingIntent contentIntent =
       PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
   builder.setContentIntent(contentIntent);
   builder.setAutoCancel(true);
   builder.setTicker(message);
   messagesManager.notify(NOTI_NO, builder.build());
   Log.i("Testing", "In display function after set notify");
 }
 @Subscribe
 public void onNewIncomingMessage(NewIncomingMessageEvent event) {
   NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
   builder.setContentTitle("New message");
   builder.setContentText(
       event.getMessage().getContact().getName() + " : " + event.getMessage().getBody());
   builder.setSmallIcon(R.drawable.ic_menu_send);
   builder.setAutoCancel(true);
   Intent intent = new Intent(context, ConversationActivity.class);
   intent.putExtra(Const.EMAIL, event.getEmail());
   PendingIntent pendingIntent =
       PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
   builder.setContentIntent(pendingIntent);
   notificationManager.notify(
       BASE_NOTIFICATON_ID + Long.valueOf(event.getMessage().getId()).intValue(),
       builder.getNotification());
 }
  private void showNotification() {

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

    // notification for the task bar
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_music);
    builder.setContentTitle(mArtist[mSong]);
    builder.setContentText(mTitle[mSong]);
    builder.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), mArtwork[mSong]));
    builder.setAutoCancel(false);
    builder.setOngoing(true);

    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
    style.setBigContentTitle(mArtist[mSong]);
    style.setSummaryText(mTitle[mSong]);
    style.bigLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_music));
    style.bigPicture(BitmapFactory.decodeResource(this.getResources(), mArtwork[mSong]));

    builder.setStyle(style);

    Intent skipIntent = new Intent(PREV_TRACK);
    PendingIntent pIntent =
        PendingIntent.getBroadcast(this, 0, skipIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.addAction(android.R.drawable.ic_media_rew, "Last Track", pIntent);

    skipIntent = new Intent(NEXT_TRACK);
    pIntent = PendingIntent.getBroadcast(this, 0, skipIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.addAction(android.R.drawable.ic_media_ff, "Next Track", pIntent);

    Intent clickIntent = new Intent(this, MainActivity.class);
    clickIntent.putExtra(MainFragment.EXTRA_TITLE_UPDATE, mTitle[mSong]);
    clickIntent.putExtra(MainFragment.EXTRA_COVER_UPDATE, mArtwork[mSong]);
    clickIntent.putExtra(MainFragment.EXTRA_ARTIST_UPDATE, mArtist[mSong]);
    clickIntent.putExtra(MainFragment.EXTRA_SONG_DURATION, mPlayer.getDuration());

    PendingIntent pendClickIntent =
        PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendClickIntent);

    Notification notification = builder.build();
    startForeground(NOTIF_ID, notification);
  }
  // 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 publishResults(
      String a, int p1, int p2, int id, long total, long done, boolean b, boolean move) {
    if (hash.get(id)) {

      mBuilder.setProgress(100, p1, false);
      mBuilder.setOngoing(true);
      int title = R.string.copying;
      if (move) title = R.string.moving;
      mBuilder.setContentTitle(utils.getString(c, title));
      mBuilder.setContentText(
          new File(a).getName()
              + " "
              + utils.readableFileSize(done)
              + "/"
              + utils.readableFileSize(total));
      int id1 = Integer.parseInt("456" + id);
      mNotifyManager.notify(id1, mBuilder.build());
      if (p1 == 100 || total == 0) {
        mBuilder.setContentTitle("Copy completed");
        if (move) mBuilder.setContentTitle("Move Completed");
        mBuilder.setContentText("");
        mBuilder.setProgress(0, 0, false);
        mBuilder.setOngoing(false);
        mBuilder.setAutoCancel(true);
        mNotifyManager.notify(id1, mBuilder.build());
        publishCompletedResult(id, id1);
      }
      DataPackage intent = new DataPackage();
      intent.setName(a);
      intent.setTotal(total);
      intent.setDone(done);
      intent.setId(id);
      intent.setP1(p1);
      intent.setP2(p2);
      intent.setMove(move);
      intent.setCompleted(b);
      hash1.put(id, intent);
      if (progressListener != null) {
        progressListener.onUpdate(intent);
        if (b) progressListener.refresh();
      }
    } else publishCompletedResult(id, Integer.parseInt("456" + id));
  }
  private void showPostUpdateNotification() {
    // Remove the old one
    mNotificationManager.cancel(NOTIFICATION_ID);

    mBuilder = new NotificationCompat.Builder(getApplicationContext());
    mBuilder.setTicker(getString(R.string.finishedTraktMovieSync));
    mBuilder.setContentTitle(getString(R.string.finishedTraktMovieSync));
    mBuilder.setSmallIcon(R.drawable.done);
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.done));
    mBuilder.setOngoing(false);
    mBuilder.setAutoCancel(true);
    mBuilder.setOnlyAlertOnce(true);

    // Build notification
    Notification updateNotification = mBuilder.build();

    // Show the notification
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATION_ID + 1000, updateNotification);
  }
  /**
   * Posts a notification in the notification bar when a transition is detected. If the user clicks
   * the notification, control goes to the MainActivity.
   */
  private void sendNotification(String notificationDetails) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder
        .setSmallIcon(R.drawable.ic_launcher)
        // In a real app, you may want to use a library like Volley
        // to decode the Bitmap.
        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
        .setColor(Color.RED)
        .setContentTitle(notificationDetails)
        .setContentText(getString(R.string.geofence_transition_notification_text))
        .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
  }
  public void showBroadCastMessage(String name, String message) {
    StatisticTracker.trackReceiveNotification(StatisticTracker.NOTIFICATION_BROADCAST_TYPE);

    PendingIntent contentIntent =
        PendingIntent.getActivity(
            mContext,
            0,
            new Intent(mContext, ChatWing.instance(mContext).getMainActivityClass()),
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(mContext.getString(R.string.broadcast_tag) + " to " + name + " ")
            .setTicker(message)
            .setContentText(message);

    builder.setContentIntent(contentIntent);
    builder.setAutoCancel(true);
    mNotificationManager.notify(message.hashCode(), builder.build());
  }
    protected void onPostExecute(String th) {

      if (th != null) {

        String total = "";
        sharedpreferences = getSharedPreferences("id_utilisateur", Context.MODE_PRIVATE);
        total = sharedpreferences.getString("total", "");

        int ancienTotal = 0;
        if (!total.equals("")) {
          ancienTotal = Integer.parseInt(total);
        }

        int nouveauTotal = Integer.parseInt(th);

        if (nouveauTotal > ancienTotal) {

          NotificationCompat.Builder mBuilder =
              new NotificationCompat.Builder((Context) context)
                  .setSmallIcon(R.drawable.common_plus_signin_btn_icon_dark)
                  .setContentTitle("ShareYourSport")
                  .setContentText("Un nouvel évènement a été crée ");

          NotificationManager mNotificationManager =
              (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          int truc = NotificationID.getID();
          mBuilder.setAutoCancel(true);
          mNotificationManager.notify(truc, mBuilder.build());

          SharedPreferences.Editor editor = sharedpreferences.edit();
          editor.putString("total", th);
          editor.commit();
        } else if (nouveauTotal < ancienTotal) {

          SharedPreferences.Editor editor = sharedpreferences.edit();
          editor.putString("total", th);
          editor.commit();
        }
      }
    }
  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());
  }