Exemple #1
0
  @SuppressWarnings("static-access")
  public static void notificationForCODetector(Context mContext) {

    Intent intent = new Intent(mContext, ReceiveRewards.class);

    int icon = R.mipmap.ic_launcher;

    int mNotificationId = 002;

    PendingIntent resultPendingIntent =
        PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);
    Notification notification =
        mBuilder
            .setSmallIcon(icon)
            .setTicker("Icon")
            .setWhen(0)
            .setAutoCancel(true)
            .setContentTitle("CO Detector Reminder")
            .setWhen(System.currentTimeMillis())
            .setStyle(new NotificationCompat.InboxStyle())
            .setContentIntent(resultPendingIntent)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setLargeIcon(
                BitmapFactory.decodeResource(mContext.getResources(), R.drawable.doc_lv_tp_2))
            .setContentText("You need to check your CO Detector")
            .build();

    NotificationManager notificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(mNotificationId, notification);
  }
  private void showNotification() {
    mBuilder =
        (NotificationCompat.Builder)
            new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_action_alarm_on)
                .setContentTitle("Time Left")
                .setContentText(formatMilliseconds(secondLeft));
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra(TIME_LEFT, secondLeft);

    // 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(MainActivity.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);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
  }
 private void notification(String message) {
   NotificationCompat.Builder mBuilder =
       (NotificationCompat.Builder)
           new NotificationCompat.Builder(this)
               .setSmallIcon(R.mipmap.ic_car)
               .setContentTitle("RideOne")
               .setContentText(message);
   // Sets an ID for the notification
   int mNotificationId = 001;
   // Gets an instance of the NotificationManager service
   NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
   // Builds the notification and issues it.
   mNotifyMgr.notify(mNotificationId, mBuilder.build());
 }
Exemple #4
0
 public static void creatHeadsUpNotification(
     Context context, Intent intent, String contentTitle, String contentText, int id) {
   PendingIntent pendingIntent = getPendingIntent(context, intent, id);
   NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
   builder.setDefaults(Notification.DEFAULT_ALL);
   builder.setSmallIcon(R.mipmap.ic_launcher);
   builder.setContentTitle(contentTitle);
   builder.setContentText(contentText);
   builder.setContentIntent(pendingIntent);
   builder.setAutoCancel(true);
   builder.setColor(Color.BLUE);
   builder.setFullScreenIntent(pendingIntent, false);
   NotificationManagerCompat nm = NotificationManagerCompat.from(context);
   nm.notify(id, builder.build());
 }
  private Notification buildWeatherNotification(ForecastItem item) {
    Date date = item.getDt_txt();
    String description = item.getWeatherData().getDescription();
    double tempMax = Math.round(item.getMain().getTempMax());

    int iconId = item.getWeatherData().getWeatherId();
    int image = setImageResourceForWeatherNotification(iconId);

    Intent intent = new Intent(getBaseContext(), DetailsActivity_.class);
    intent.putExtra("id", item.getId());

    PendingIntent pendingIntent =
        PendingIntent.getActivity(this, NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    return builder
        .setAutoCancel(true)
        .setOngoing(true)
        .setSmallIcon(ImageUtils.getIconResourceForWeatherCondition((iconId)))
        .setLargeIcon(BitmapFactory.convert(ContextCompat.getDrawable(getBaseContext(), image)))
        .setContentTitle(getBaseContext().getString(R.string.app_name))
        .setContentText(DateUtils.getFormattedDate(date))
        .setSubText(description + "\t" + tempMax + "°C")
        .setNumber(++NOTIFICATION_NUMBER)
        .setContentIntent(pendingIntent)
        .setDeleteIntent(NotificationEventReceiver.getDeleteIntent(this))
        .build();
  }
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private void triggerNotification(String info, String info2, Context context, Intent intent) {
    NotificationCompat.Builder mBuilder =
        (NotificationCompat.Builder)
            new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_directions_bus_black_48dp)
                .setContentTitle(context.getResources().getString(R.string.app_name))
                .setAutoCancel(true)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(info2))
                .setContentText(info)
                .setVibrate(null)
                .setSound(null)
                .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0));

    // Notifications
    if (Repository.getInstance().getRingtoneNotification().equals(true)) {
      // Ton
      Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      mBuilder.setSound(alarmSound);
    }
    if (Repository.getInstance().getVibrationNotification().equals(true)) {
      // Vibration
      mBuilder.setVibrate(new long[] {1000, 1000, 1000, 1000, 1000});
    }
    if (Repository.getInstance().getLedNotification().equals(true)) {
      // LED
      mBuilder.setLights(ContextCompat.getColor(context, R.color.ledColour), 1000, 1000);
    }

    // Creates an explicit intent for an Activity
    Intent resultIntent = new Intent(context, MainActivity.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
    // application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);

    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(418, mBuilder.build());
  }
Exemple #7
0
 public static void create(
     Context context, Intent intent, String contentTitle, String contentText, int id) {
   PendingIntent pendingIntent = getPendingIntent(context, intent, id);
   NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
   builder.setDefaults(Notification.DEFAULT_ALL);
   builder.setSmallIcon(R.mipmap.ic_launcher);
   builder.setContentTitle(contentTitle);
   builder.setContentText(contentText);
   builder.setContentIntent(pendingIntent);
   builder.setAutoCancel(true);
   builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
   NotificationManagerCompat nm = NotificationManagerCompat.from(context);
   nm.notify(id, builder.build());
 }
 public void lanza(View v) {
   NotificationCompat.Builder mBuilder =
       (NotificationCompat.Builder)
           new NotificationCompat.Builder(this)
               .setSmallIcon(R.mipmap.ic_launcher)
               .setContentTitle("Mi notificación")
               .setContentText("Hola Mundo!");
   Intent resultIntent = new Intent(this, MainActivity.class);
   PendingIntent resultPendingIntent =
       PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
   mBuilder.setContentIntent(resultPendingIntent);
   // Sets an ID for the notification
   int mNotificationId = 001;
   // Gets an instance of the NotificationManager service
   NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
   // Builds the notification and issues it.
   mNotifyMgr.notify(mNotificationId, mBuilder.build());
 }
Exemple #9
0
 public static void sendBroadcastNotification(
     Context context, Intent intent, String contentTitle, String contentText, int id) {
   NotificationManager manager =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   PendingIntent pendingIntent =
       PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
   NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
   builder.setDefaults(Notification.DEFAULT_ALL);
   builder.setSmallIcon(R.mipmap.ic_launcher);
   builder.setContentTitle(contentTitle);
   builder.setContentText(contentText);
   builder.setContentIntent(pendingIntent);
   builder.setVibrate(new long[] {200});
   builder.setAutoCancel(true);
   builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
   Notification n = builder.build();
   manager.notify(id, n);
 }
  public void cambia(View v) {
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // Sets an ID for the notification, so it can be updated
    int notifyID = 1;
    NotificationCompat.Builder mNotifyBuilder =
        (NotificationCompat.Builder)
            new NotificationCompat.Builder(this)
                .setContentTitle("Nuevo Mensaje")
                .setContentText("Tienes mensajes nuevos!")
                .setSmallIcon(R.mipmap.ic_launcher);

    // Start of a loop that processes data and then notifies the user
    String currentText = "Texto";
    mNotifyBuilder.setContentText(currentText).setNumber(++numMessages);
    // Because the ID remains unchanged, the existing notification is
    // updated.
    mNotificationManager.notify(notifyID, mNotifyBuilder.build());
  }
 /**
  * 建立和刷新通知
  *
  * @param progress 进度
  */
 private void showNotification(int progress) {
   if (mBuilder == null) {
     mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     mBuilder = new NotificationCompat.Builder(this);
     mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
     mBuilder.setSmallIcon(R.mipmap.ic_launcher);
     mBuilder.setTicker("正在下载...");
     mBuilder.setContentTitle("正在下载...");
     mBuilder.setWhen(System.currentTimeMillis());
   }
   mBuilder.setProgress(MAX_PROGRESS, progress, false);
   mBuilder.setContentText(progress + "%");
   Notification notification = mBuilder.build();
   mNotificationManager.notify(NOTIFICATION_ID, notification);
 }
  public void launchNotification(Context context, String title, String message) {

    // Extender for Android Wear
    NotificationCompat.WearableExtender wearableExtender =
        new NotificationCompat.WearableExtender()
            .setBackground(
                BitmapFactory.decodeResource(context.getResources(), R.drawable.library_wear_bg));

    // Build notification
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
    notificationBuilder.setSmallIcon(R.drawable.ic_stat_name);
    notificationBuilder.setLargeIcon(
        BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
    notificationBuilder.setContentTitle(title);
    notificationBuilder.setContentText(message);
    notificationBuilder.setLights(ContextCompat.getColor(context, R.color.pureRed), 2000, 2000);
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.extend(wearableExtender);

    // TODO: criar extra no intent pra tratar abertura da pag da biblio!
    Intent resultIntent = new Intent(context, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    int idNotify = 1;
    mNotificationManager.notify(idNotify, notificationBuilder.build());
  }
 @Override
 protected void onHandleIntent(Intent intent) {
   Log.d(getClass().getSimpleName(), "onHandleIntent, started handling a notification event");
   try {
     String action = intent.getAction();
     if (ACTION_START.equals(action) && (WeatherRepository.getActualWeatherForecast()) != null) {
       processStartNotification(WeatherRepository.getActualWeatherForecast());
       if (builder != null) {
         NotificationIntentService.getNotificationManager()
             .notify(NOTIFICATION_ID, builder.build());
       }
     }
     if (ACTION_DELETE.equals(action)) {
       processDeleteNotification(intent);
     }
   } finally {
     WakefulBroadcastReceiver.completeWakefulIntent(intent);
   }
 }
Exemple #14
0
  public void simpleNotification() {
    //        获取NotificationManager实例
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    //        构造Notification.Builder 对象
    NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this);

    //        设置Notification图标
    builder.setSmallIcon(R.mipmap.ic_launcher);
    // builder.setLargeIcon(myIcon);
    //        设置Notification tickertext
    builder.setTicker("A new Message");
    //        设置通知的题目
    Date dNow = new Date();
    SimpleDateFormat ft = new SimpleDateFormat("hh:mm:ss");
    String time = ft.format(dNow);
    builder.setContentTitle(this.todayWeather.getCity() + "\t" + "更新时间为" + time);
    //        设置通知的内容
    builder.setContentText("今天温度为:" + this.todayWeather.getWendu() + "℃");
    builder.setContentInfo("Info");
    //        设置通知可以被自动取消
    builder.setAutoCancel(true);
    //        设置通知栏显示的Notification按时间排序
    builder.setWhen(System.currentTimeMillis());
    //        设置其他物理属性,包括通知提示音、震动、屏幕下方LED灯闪烁
    builder.setSound(
        RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); // 这里设置一个本地文件为提示音
    //        builder.setVibrate(new long[]{1000,1000,1000,1000});
    builder.setLights(Color.BLUE, 0, 1);
    //        设置该通知点击后将要启动的Intent,这里需要注意PendingIntent的用法,构造方法中的四个参数(context,int
    // requestCode,Intent,int flags);
    Intent intent = new Intent(MainActivity.this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
    builder.setContentIntent(pi);

    //        实例化Notification

    Notification notification =
        builder.build(); // notify(int id,notification对象);id用来标示每个notification
    manager.notify(1, notification);
  }
Exemple #15
0
  private void notifyInToolBar() {
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this);
    builder.setTicker("天气信息已经更新!");
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setWhen(System.currentTimeMillis());
    builder.setAutoCancel(true);
    //        设置自定义RemoteView
    RemoteViews view = new RemoteViews(getPackageName(), R.layout.remote_view);

    builder.setContent(view);
    PendingIntent pi =
        PendingIntent.getActivity(
            MainActivity.this, 1, new Intent(MainActivity.this, MainActivity.class), 0);
    builder.setContentIntent(pi);
    builder.setVibrate(new long[] {1000, 1000, 1000, 1000});
    builder.setLights(Color.RED, 0, 1);
    builder.setOngoing(true);
    manager.notify(2, builder.build());
  }
  /**
   * Build a new notification. To update the progress on the notification, use {@link
   * #updateProgress(int, int)} instead.
   *
   * @param episode The episode playing.
   * @param paused Playback state, <code>true</code> for paused.
   * @param canSeek If the currently played media is seekable.
   * @param position The current playback progress.
   * @param duration The length of the current episode.
   * @param session The media session representing current playback.
   * @return The notification to display.
   */
  @NonNull
  public Notification build(
      Episode episode,
      boolean paused,
      boolean canSeek,
      int position,
      int duration,
      MediaSessionCompat session) {
    // 0. Prepare the main intent (leading back to the app)
    appIntent.putExtra(PODCAST_URL_KEY, episode.getPodcast().getUrl());
    appIntent.putExtra(EPISODE_URL_KEY, episode.getMediaUrl());
    final PendingIntent backToAppIntent =
        PendingIntent.getActivity(context, 0, appIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    // 1. Create the notification builder and set values
    notificationBuilder = new NotificationCompat.Builder(context);
    notificationBuilder
        .setContentIntent(backToAppIntent)
        .setTicker(episode.getName())
        .setSmallIcon(R.drawable.ic_stat)
        .setContentTitle(episode.getName())
        .setContentText(episode.getPodcast().getName())
        .setWhen(0)
        .setProgress(duration, position, false)
        .setOngoing(true);

    // 2. Load large image if available, see onBitmapLoaded() below
    if (episode.getPodcast().hasLogoUrl())
      Picasso.with(context)
          .load(episode.getPodcast().getLogoUrl())
          .resizeDimen(
              android.R.dimen.notification_large_icon_width,
              android.R.dimen.notification_large_icon_height)
          .into(this);

    // 3. Add actions to notification
    notificationBuilder.addAction(stopAction);
    if (canSeek) notificationBuilder.addAction(rewindAction);
    if (paused) notificationBuilder.addAction(playAction);
    else notificationBuilder.addAction(pauseAction);
    if (canSeek) notificationBuilder.addAction(forwardAction);

    // 4. Apply other notification features
    NotificationCompat.MediaStyle style =
        new NotificationCompat.MediaStyle().setMediaSession(session.getSessionToken());
    // Make sure not to show rew/ff icons for live streams
    if (canSeek) style.setShowActionsInCompactView(1, 2, 3); // rewind, toggle play, forward
    else style.setShowActionsInCompactView(0, 1); // stop, toggle play

    notificationBuilder.setStyle(style);
    notificationBuilder.setColor(ContextCompat.getColor(context, R.color.theme_dark));
    notificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    notificationBuilder.setCategory(NotificationCompat.CATEGORY_TRANSPORT);

    return notificationBuilder.build();
  }
 /**
  * Update the last notification build with a new progress and duration and rebuild it leaving all
  * the other data intact. Only call this after build().
  *
  * @param position The new progress position.
  * @param duration The length of the current episode.
  * @return The updated notification to display or <code>null</code> if called before build().
  * @see #build(Episode, boolean, boolean, int, int, MediaSessionCompat)
  */
 @Nullable
 public Notification updateProgress(int position, int duration) {
   return notificationBuilder == null
       ? null
       : notificationBuilder.setProgress(duration, position, false).build();
 }
 @Override
 public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
   // Set bitmap on the notification builder, this will be picked up
   // when updateProgress is called the next time
   notificationBuilder.setLargeIcon(bitmap);
 }
 private void updateNotification(int secondLeft) {
   int numMessages = 0;
   mBuilder.setContentText(formatMilliseconds(secondLeft)).setNumber(++numMessages);
   mNotificationManager.notify(mId, mBuilder.build());
 }
Exemple #20
0
 public static void createBigNotification(
     Context context,
     Intent intent,
     String contentTitle,
     String contentText,
     List<String> lista,
     int id) {
   //        PendingIntent pendingIntent = getPendingIntent(context, intent, id);
   PendingIntent pendingIntent =
       PendingIntent.getActivity(
           context,
           0,
           new Intent(context, TodoListActivity.class),
           PendingIntent.FLAG_UPDATE_CURRENT);
   int size = lista.size();
   NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
   inboxStyle.setBigContentTitle(contentTitle);
   for (String s : lista) {
     inboxStyle.addLine(s);
   }
   inboxStyle.setSummaryText(contentText);
   NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
   builder.setDefaults(Notification.DEFAULT_ALL);
   builder.setSmallIcon(R.mipmap.ic_launcher);
   builder.setContentTitle(contentTitle);
   builder.setContentText(contentText);
   builder.setContentIntent(pendingIntent);
   builder.setAutoCancel(true);
   builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
   builder.setNumber(size);
   builder.setStyle(inboxStyle);
   NotificationManagerCompat nm = NotificationManagerCompat.from(context);
   nm.notify(id, builder.build());
 }