示例#1
0
  @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());
  }
示例#2
0
  @Override
  public void vaddLogNotif(final Context ctxt, final boolean flag) {

    if (!flag) {
      vcancel(ctxt, LOG_TAG, NotifUtil.LOGNOTIFID);
      return;
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctxt);
    Intent intent =
        new Intent(ctxt, WifiFixerActivity.class)
            .setAction(Intent.ACTION_MAIN)
            .setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    builder.setContentIntent(PendingIntent.getActivity(ctxt, 0, intent, 0));
    builder.setOngoing(true);
    builder.setOnlyAlertOnce(true);
    builder.setOngoing(true);
    builder.setSmallIcon(R.drawable.logging_enabled);
    builder.setContentTitle(ctxt.getString(R.string.logservice));
    builder.setContentText(getLogString(ctxt).toString());

    /*
     * Fire the notification
     */
    notify(ctxt, NotifUtil.LOGNOTIFID, LOG_TAG, builder.build());
  }
  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;
  }
示例#4
0
  /**
   * 在notifiaction中显示进度条
   *
   * @return
   */
  private NotificationCompat.Builder displayProgressInNotification() {
    // TODO 这个图片不设置的话,通知出不来
    builder.setSmallIcon(R.drawable.icon);
    builder.setContentTitle("下载文件");
    builder.setContentText("正在下载。。。");
    new Thread(
            new Runnable() {

              @Override
              public void run() {
                // TODO <=100
                for (int i = 0; i <= 100; i += 5) {
                  // 将setProgress的第三个参数设为true即可显示为无明确进度的进度条样式,而不是没有进度条
                  builder.setProgress(100, i, false);
                  manager.notify(0, builder.build());

                  try {
                    Thread.sleep(5 * 100);
                  } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }
                builder.setContentText("下载完成");
                builder.setProgress(0, 0, false);

                // id相同,使用新设置的属性的通知,代替之前的通知
                manager.notify(0, builder.build());
              }
            })
        .start();

    return builder;
  }
示例#5
0
  private void showBigNotification(
      Bitmap bitmap,
      NotificationCompat.Builder mBuilder,
      int icon,
      String title,
      String message,
      String timeStamp,
      PendingIntent resultPendingIntent,
      Uri alarmSound) {
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    bigPictureStyle.setBigContentTitle(title);
    bigPictureStyle.setSummaryText(Html.fromHtml(message).toString());
    bigPictureStyle.bigPicture(bitmap);
    Notification notification;
    notification =
        mBuilder
            .setSmallIcon(icon)
            .setTicker(title)
            .setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(bigPictureStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setSmallIcon(R.drawable.ic_notification_small)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .build();

    NotificationManager notificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Config.NOTIFICATION_ID_BIG_IMAGE, notification);
  }
  @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);
    }
  }
  @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();
  }
  public void notificar(
      int idNotificacao,
      String titulo,
      String texto,
      String ticker,
      Class classe,
      Parada parada,
      int icone) {
    mBuilder.setContentTitle(titulo).setContentText(texto).setTicker(ticker);
    mBuilder.setSmallIcon(icone);
    Intent resultIntent = new Intent(con, classe);

    resultIntent.putExtra("nomeparada", parada.getNome());
    resultIntent.putExtra("codigoparada", parada.getCodigoParada());

    SimpleDateFormat dateFormat_hora = new SimpleDateFormat("HH:mm:ss");
    Date data = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(data);
    Date data_atual = cal.getTime();
    String hora_atual = dateFormat_hora.format(data_atual);

    resultIntent.putExtra("infotempoatual", hora_atual);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(con);
    stackBuilder.addParentStack(classe);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mNotificationManager.notify(idNotificacao, mBuilder.build());
  }
示例#9
0
  public void updateNotification() {
    if (!Preferences.isNotificationEnabled() || !playServicesAvailable) return;

    String title = null;
    String subtitle = null;
    long time = 0;

    if ((this.lastPublishedLocation != null) && Preferences.isNotificationLocationEnabled()) {
      time = this.lastPublishedLocationTime.getTime();

      if ((this.lastPublishedLocation.getGeocoder() != null)
          && Preferences.isNotificationGeocoderEnabled()) {
        title = this.lastPublishedLocation.toString();
      } else {
        title = this.lastPublishedLocation.toLatLonString();
      }
    } else {
      title = this.context.getString(R.string.app_name);
    }

    subtitle =
        ServiceLocator.getStateAsString(this.context)
            + " | "
            + ServiceBroker.getStateAsString(this.context);

    notificationBuilder.setContentTitle(title);
    notificationBuilder
        .setSmallIcon(R.drawable.ic_notification)
        .setContentText(subtitle)
        .setPriority(android.support.v4.app.NotificationCompat.PRIORITY_MIN);
    if (time != 0) notificationBuilder.setWhen(this.lastPublishedLocationTime.getTime());

    this.notification = notificationBuilder.build();
    this.context.startForeground(Defaults.NOTIFCATION_ID, this.notification);
  }
  @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();
  }
示例#11
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 initBuilder(String title, String content) {
   builder = new NotificationCompat.Builder(baseActivity.getBaseContext());
   builder.setContentTitle(title);
   builder.setContentText(content);
   builder.setSmallIcon(R.drawable.ic_lets_go);
   builder.setPriority(NotificationCompat.PRIORITY_MAX);
   builder.setOngoing(true);
 }
  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());
  }
    public PostUploadNotifier(Post post) {
      // add the uploader to the notification bar
      mNotificationManager =
          (NotificationManager) SystemServiceFactory.get(mContext, Context.NOTIFICATION_SERVICE);

      mNotificationBuilder = new NotificationCompat.Builder(getApplicationContext());
      mNotificationBuilder.setSmallIcon(android.R.drawable.stat_sys_upload);
      mNotificationId = (new Random()).nextInt() + post.getLocalTableBlogId();
      startForeground(mNotificationId, mNotificationBuilder.build());
    }
示例#15
0
  private void preExecute() {
    taskIsRunning = true;
    notification = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    builder = new NotificationCompat.Builder(getApplicationContext());
    builder.setContentTitle("Searching for new music...");
    builder.setContentText("Looking for music files...");
    builder.setSmallIcon(R.drawable.ic_launcher);

    builder.setProgress(100, 0, true);
    notification.notify(id, builder.build());
  }
 public void notcompleted(String title, String description) {
   if (mNotificationManager != null) {
     mBuilder
         .setSmallIcon(android.R.drawable.stat_sys_download_done)
         .setProgress(0, 0, false)
         .setContentTitle(title)
         .setContentText(description)
         .setAutoCancel(true)
         .setOngoing(false);
     mNotificationManager.notify(notificationId, mBuilder.build());
   }
 }
示例#17
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();
  }
示例#18
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());
  }
  private void showNotification() {
    boolean notificationEnable =
        mPreferences.getBoolean(getString(R.string.notifications_enable), true);
    if (notificationEnable) {
      NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(getBaseContext());
      notifBuilder
          .setSmallIcon(android.R.drawable.ic_dialog_info)
          .setContentTitle(getString(R.string.notification_title))
          .setTicker(getString(R.string.notification_ticker));

      startForeground(Constants.NOTIFICATION_ID, notifBuilder.build());
    }
  }
 private static Notification updateSendDirectMessageNotification(
     final Context context,
     final NotificationCompat.Builder builder,
     final int progress,
     final String message) {
   builder.setContentTitle(context.getString(R.string.sending_direct_message));
   if (message != null) {
     builder.setContentText(message);
   }
   builder.setSmallIcon(R.drawable.ic_stat_send);
   builder.setProgress(100, progress, progress >= 100 || progress <= 0);
   builder.setOngoing(true);
   return builder.build();
 }
 private static Notification updateUpdateStatusNotification(
     final Context context,
     final NotificationCompat.Builder builder,
     final int progress,
     final ParcelableStatusUpdate status) {
   builder.setContentTitle(context.getString(R.string.updating_status_notification));
   if (status != null) {
     builder.setContentText(status.text);
   }
   builder.setSmallIcon(R.drawable.ic_stat_send);
   builder.setProgress(100, progress, progress >= 100 || progress <= 0);
   builder.setOngoing(true);
   return 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();
 }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "Received start id " + startId + ": " + intent);
    if (intent != null) {
      // config = Config.fromByteArray(intent.getByteArrayExtra("config"));
      config = (Config) intent.getParcelableExtra("config");
      Log.i(TAG, "Config: " + config.toString());

      // Build a Notification required for running service in foreground.
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
      builder.setContentTitle(config.getNotificationTitle());
      builder.setContentText(config.getNotificationText());
      builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
      if (config.getNotificationIcon() != null) {
        builder.setSmallIcon(getPluginResource(config.getSmallNotificationIcon()));
        builder.setLargeIcon(
            BitmapFactory.decodeResource(
                getApplication().getResources(),
                getPluginResource(config.getLargeNotificationIcon())));
      }
      if (config.getNotificationIconColor() != null) {
        builder.setColor(this.parseNotificationIconColor(config.getNotificationIconColor()));
      }

      setClickEvent(builder);

      Notification notification = builder.build();
      notification.flags |=
          Notification.FLAG_ONGOING_EVENT
              | Notification.FLAG_FOREGROUND_SERVICE
              | Notification.FLAG_NO_CLEAR;
      startForeground(startId, notification);
    }

    // We want this service to continue running until it is explicitly stopped
    return START_REDELIVER_INTENT;
  }
  private NotificationCompat.Builder setNotification(final long id) {

    DownloadInfoRunnable info = getDownload(id);

    final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

    // TODO
    Intent onClick = new Intent();
    onClick.setClassName(
        getPackageName(), /*Aptoide.getConfiguration().*/ getStartActivityClass().getName());
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.setAction(Intent.ACTION_VIEW);
    onClick.putExtra("fromDownloadNotification", true);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction =
        PendingIntent.getActivity(
            getApplicationContext(), 0, onClick, PendingIntent.FLAG_UPDATE_CURRENT);

    int size = DownloadUtils.dpToPixels(getApplicationContext(), 36);

    Bitmap icon = null;

    try {
      // icon =
      // DownloadUtils.decodeSampledBitmapFromResource(ImageLoader.getInstance().getDiscCache().get(info.getDownload().getIcon()).getAbsolutePath(), size, size);
      icon =
          GlideUtils.downloadOnlyFromCache(
              Aptoide.getContext(), info.getDownload().getIcon(), size, size);
    } catch (Exception e) {
      e.printStackTrace();
    }

    mBuilder.setOngoing(true);
    mBuilder.setContentTitle(
        getString(R.string.aptoide_downloading, Aptoide.getConfiguration().getMarketName()));
    mBuilder.setContentText(info.getDownload().getName());
    if (icon != null) mBuilder.setLargeIcon(icon);
    mBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
    mBuilder.setProgress(0, 0, true);
    mBuilder.setContentIntent(onClickAction);
    // Log.d("download-trace", "ETA: " + info.getEta());
    if (info.getEta() > 0) {
      String remaining = DownloadUtils.formatEta(info.getEta(), "");
      mBuilder.setContentInfo("ETA: " + (!remaining.equals("") ? remaining : "0s"));
    }

    return mBuilder;
  }
示例#25
0
    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);
    }
示例#26
0
  public void updateTicker(String text) {
    Log.v(this.toString(), "Updating ticker with " + text);
    notificationBuilder.setTicker(text + ((this.even = this.even ? false : true) ? " " : ""));
    notificationBuilder.setSmallIcon(R.drawable.ic_notification);
    this.notificationManager.notify(Defaults.NOTIFCATION_ID, notificationBuilder.build());

    // Clear ticker
    notificationBuilder.setTicker(null);
    this.notificationManager.notify(Defaults.NOTIFCATION_ID, notificationBuilder.build());

    // if the notification is not enabled, the ticker will create an empty
    // one that we get rid of
    if (!Preferences.isNotificationEnabled())
      this.notificationManager.cancel(Defaults.NOTIFCATION_ID);
  }
示例#27
0
  private void showSmallNotification(
      NotificationCompat.Builder mBuilder,
      int icon,
      String title,
      String message,
      String timeStamp,
      PendingIntent resultPendingIntent,
      Uri alarmSound) {

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    if (Config.appendNotificationMessages) {
      // store the notification in shared pref first
      IsmartApp.getInstance().getPrefManager().addNotification(message);

      // get the notifications from shared preferences
      String oldNotification = IsmartApp.getInstance().getPrefManager().getNotifications();

      List<String> messages = Arrays.asList(oldNotification.split("\\|"));

      for (int i = messages.size() - 1; i >= 0; i--) {
        inboxStyle.addLine(messages.get(i));
      }
    } else {
      inboxStyle.addLine(message);
    }

    Notification notification;
    notification =
        mBuilder
            .setSmallIcon(icon)
            .setTicker(title)
            .setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(inboxStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setSmallIcon(R.drawable.ic_notification_small)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .build();

    NotificationManager notificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Config.NOTIFICATION_ID, 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());
  }
示例#29
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());
 }