Пример #1
1
  private void showNotification() {
    try {
      // add notification to status bar
      NotificationCompat.Builder builder =
          new NotificationCompat.Builder(this)
              .setSmallIcon(R.drawable.icon)
              .setLargeIcon(AudioUtil.getCover(this, mCurrentMedia, 64))
              .setContentTitle(mCurrentMedia.getTitle())
              .setTicker(mCurrentMedia.getTitle() + " - " + mCurrentMedia.getArtist())
              .setContentText(
                  Util.isJellyBeanOrLater()
                      ? mCurrentMedia.getArtist()
                      : mCurrentMedia.getSubtitle())
              .setContentInfo(mCurrentMedia.getAlbum())
              .setAutoCancel(false)
              .setOngoing(true);

      Intent notificationIntent = new Intent(this, AudioPlayerActivity.class);
      notificationIntent.setAction(Intent.ACTION_MAIN);
      notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
      notificationIntent.putExtra(START_FROM_NOTIFICATION, true);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

      builder.setContentIntent(pendingIntent);
      startForeground(3, builder.build());
    } catch (NoSuchMethodError e) {
      // Compat library is wrong on 3.2
      // http://code.google.com/p/android/issues/detail?id=36359
      // http://code.google.com/p/android/issues/detail?id=36502
    }
  }
Пример #2
1
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private void showJellyBean() {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this.activity)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(this.title)
            .setContentText(this.text);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(activity, activity.getClass());

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

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

    // 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) activity.getSystemService(Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(this.id, mBuilder.build());
  }
Пример #3
0
  private void showInstallNotification(ScanResult result) {

    if (result != null) {

      PackageInfo pi = null;

      PackageManager pm = getApplicationContext().getPackageManager();

      try {
        pi = pm.getPackageInfo(packageName, 0);
      } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
      }
      String appName = pm.getApplicationLabel(pi.applicationInfo).toString();
      if (result.dangerCount.equals(0)) {
        NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.small_icon)
                .setContentTitle(appName + getString(R.string.app_is_safe))
                .setContentText(getString(R.string.open_app))
                .setAutoCancel(true);
        Intent resultIntent = pm.getLaunchIntentForPackage(packageName);
        PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                getApplicationContext(), 1, resultIntent, 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(0, mBuilder.build());
      } else {
        NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.small_icon)
                .setContentTitle(appName + getString(R.string.app_unsafe))
                .setContentText(getString(R.string.click_show_result))
                .setAutoCancel(true);
        Intent resultIntent = new Intent(getBaseContext(), ResultActivity.class);

        // resultIntent.putExtra("CALLED_FROM", ScanService.class.getName());
        Bundle bundle = new Bundle();
        bundle.putParcelable("SCAN_RESULT", result);
        resultIntent.putExtras(bundle);

        PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                getApplicationContext(), 1, resultIntent, 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(0, mBuilder.build());
      }
    }
  }
Пример #4
0
  private void createNotification() {
    Log.v(this.toString(), "createNotification");
    //
    notificationBuilder = new NotificationCompat.Builder(this.context);

    Intent resultIntent = new Intent(this.context, ActivityLauncher.class);
    resultIntent.setAction("android.intent.action.MAIN");
    resultIntent.addCategory("android.intent.category.LAUNCHER");

    resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

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

    notificationBuilder.setContentIntent(resultPendingIntent);

    this.notificationIntent =
        ServiceProxy.getPendingIntentForService(
            this.context,
            ServiceProxy.SERVICE_LOCATOR,
            Defaults.INTENT_ACTION_PUBLISH_LASTKNOWN,
            null);
    notificationBuilder.addAction(
        R.drawable.ic_action_upload,
        this.context.getString(R.string.publish),
        this.notificationIntent);
    updateNotification();
  }
Пример #5
0
  public void sendNotification() {
    //
    //      Create an explicit intent for a MainActivity in my app
    Intent mainActivityIntent = new Intent(activity, CallActivity.class);
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(activity)
            .setSmallIcon(R.drawable.notification_template_icon_bg)
            .setContentTitle(" Title (test):")
            .setContentText("content")
            .setAutoCancel(true);

    // 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 my application
    // to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(activity);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Add the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(mainActivityIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationBuilder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
        (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(TEST_NOTIF_ID, notificationBuilder.build());
  }
Пример #6
0
  /**
   * Show a notification while this service is running.
   *
   * @param msg
   */
  private void showNotification(String username, String msg) {
    // Set the icon, scrolling text and TIMESTAMP
    String title = "AndroidIM: You got a new Message! (" + username + ")";

    String text = username + ": " + ((msg.length() < 5) ? msg : msg.substring(0, 5) + "...");

    // NotificationCompat.Builder notification = new
    // NotificationCompat.Builder(R.drawable.stat_sample, title,System.currentTimeMillis());
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.stat_sample)
            .setContentTitle(title)
            .setContentText(text);

    Intent i = new Intent(this, Messaging.class);
    i.putExtra(FriendInfo.USERNAME, username);
    i.putExtra(MessageInfo.MESSAGETEXT, msg);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

    // Set the info for the views that show in the notification panel.
    // msg.length()>15 ? MSG : msg.substring(0, 15);
    mBuilder.setContentIntent(contentIntent);

    mBuilder.setContentText("New message from " + username + ": " + msg);

    // TODO: it can be improved, for instance message coming from same user may be concatenated
    // next version

    // Send the notification.
    // We use a layout id because it is a unique number.  We use it later to cancel.
    mNM.notify((username + msg).hashCode(), mBuilder.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();
  }
Пример #8
0
    public void notify(String sender, String message, String tripid, Context context) {
      NotificationCompat.Builder mBuilder =
          new NotificationCompat.Builder(context)
              .setSmallIcon(R.drawable.ic_launcher)
              .setContentTitle(sender)
              .setContentText(message);
      // Creates an explicit intent for an Activity in your app
      Intent resultIntent = new Intent(context, ChatActivity.class);
      resultIntent.putExtra("email", sender);
      resultIntent.putExtra("message", message);
      resultIntent.putExtra("tripid", tripid);

      // 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(ChatActivity.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) context.getSystemService(Context.NOTIFICATION_SERVICE);
      int mId = 0;
      Notification nf = mBuilder.build();
      nf.defaults = Notification.DEFAULT_ALL;
      nf.flags = Notification.FLAG_AUTO_CANCEL;

      // mId allows you to update the notification later on.
      mNotificationManager.notify(mId, nf);
    }
  public void pushNotification(String msg, Boolean setPendingIntent) {
    mNotificationManager =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.mipmap.fashion_app_logo);

    Intent notifIntent;
    PendingIntent pendingIntent = null;

    if (setPendingIntent) {
      notifIntent =
          new Intent(this, ClientLoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
      pendingIntent =
          PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setLargeIcon(icon)
            .setColor(R.color.primary)
            .setSmallIcon(R.mipmap.ic_trending)
            .setContentTitle("Marshmallow Notification")
            .setContentText(msg)
            .setAutoCancel(true)
            .setPriority(Notification.FLAG_HIGH_PRIORITY)
            .setDefaults(DEFAULT_ALL);

    if (setPendingIntent) {
      mBuilder.setContentIntent(pendingIntent);
    }

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
  }
  /** Sets up a notification shortcut in the system bar */
  public static void setupNotification() {
    Context context = ApplicationContext.getInstance();
    String notificationService = Context.NOTIFICATION_SERVICE;
    mNotificationManager = (NotificationManager) context.getSystemService(notificationService);
    Intent notificationIntent = new Intent(context, MainFragmentActivity.class);
    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
      mBuilder =
          new NotificationCompat.Builder(ApplicationContext.getInstance())
              .setSmallIcon(R.drawable.ic_stat_notification)
              .setContentTitle(context.getResources().getText(R.string.app_name))
              .setContentText(context.getResources().getText(R.string.go_to_app))
              .setWhen(0);
    else
      mBuilder =
          new NotificationCompat.Builder(ApplicationContext.getInstance())
              .setSmallIcon(R.drawable.ic_stat_notification)
              .setContentTitle(context.getResources().getText(R.string.app_name))
              .setContentText(context.getResources().getText(R.string.go_to_app));

    mBuilder.setContentIntent(contentIntent);
    // mId allows you to update the notification later on.
    int mId = 1;
    Notification shortcutNotification = mBuilder.build();
    shortcutNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    mNotificationManager.notify(mId, shortcutNotification);

    ApplicationContext.getInstance().notificationIsShowing = true;
  }
  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);
    }
  }
Пример #12
0
  public static void notifAudioRecording(Context context, long timeLeft, long timeTotal) {
    NotificationManager nm =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Resources res = context.getResources();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder
        .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0))
        .setSmallIcon(R.drawable.ic_launcher)
        .setTicker(
            res.getString(R.string.audio_is_recording)
                .replace("#n#", String.valueOf(timeLeft / 1000 / 60)))
        .setWhen(System.currentTimeMillis() + timeLeft)
        .setAutoCancel(false)
        .setContentTitle(res.getString(R.string.sos))
        .setContentText(
            res.getString(R.string.audio_is_recording)
                .replace("#n#", String.valueOf(timeLeft / 1000 / 60)))
        .setWhen(System.currentTimeMillis() + timeLeft)
        .setOngoing(true)
        .setProgress((int) (timeTotal / 1000), (int) ((timeTotal - timeLeft) / 1000), false)
        .setOnlyAlertOnce(true)
        .setSound(null)
        .setPriority(1000);

    nm.notify(NOTIF_AUDIO_RECORD_CODE, builder.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());
  }
Пример #14
0
  public static void notifDelayedSOS(Context context, long timeLeft, long timeTotal) {
    Intent notificationIntent = new Intent(context, SosActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.putExtra(SosActivity.FRAGMENT_KEY, DelayedSosFragment.class.getName());
    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

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

    Resources res = context.getResources();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder
        .setContentIntent(contentIntent)
        .setSmallIcon(R.drawable.ic_launcher)
        .setTicker(
            res.getString(R.string.sos_after).replace("#n#", String.valueOf(timeLeft / 1000 / 60)))
        .setWhen(System.currentTimeMillis() + timeLeft)
        .setAutoCancel(false)
        .setContentTitle(res.getString(R.string.sos))
        .setContentText(
            res.getString(R.string.sos_after).replace("#n#", String.valueOf(timeLeft / 1000 / 60)))
        .setWhen(System.currentTimeMillis() + timeLeft)
        .setOngoing(true)
        .setProgress((int) (timeTotal / 1000), (int) ((timeTotal - timeLeft) / 1000), false)
        .setOnlyAlertOnce(false)
        .setPriority(1000);

    nm.notify(NOTIF_DELAYED_SOS_CODE, builder.build());
  }
Пример #15
0
  @Override
  public void onEvent(EMNotifierEvent event) {
    switch (event.getEvent()) {
      case EventNewMessage:
        {
          EMMessage message = (EMMessage) event.getData();
          String userId = null;
          userId = message.getFrom();

          NotificationCompat.Builder mBuilder =
              new NotificationCompat.Builder(this)
                  .setSmallIcon(getApplicationContext().getApplicationInfo().icon)
                  .setWhen(System.currentTimeMillis())
                  .setContentTitle("有新消息了!")
                  .setContentText("A+")
                  .setAutoCancel(true);
          Intent resultIntent = new Intent(this, ChatActivity.class);
          resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
          resultIntent.putExtra("notification", true);
          resultIntent.putExtra("easemobId", userId);
          TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
          stackBuilder.addParentStack(ChatActivity.class);
          stackBuilder.addNextIntent(resultIntent);
          PendingIntent resultPendingIntent =
              stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
          mBuilder.setContentIntent(resultPendingIntent);
          NotificationManager mNotificationManager =
              (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

          mNotificationManager.notify(0, mBuilder.build());
        }
    }
  }
Пример #16
0
  public void displayNotification(
      String msg, String msg2, int mID) // msg is big msg, msg2 is lower underneath
      {

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle(msg)
            .setContentText(msg2);
    // long[] vib = {0,200};
    // mBuilder.setVibrate(vib); // does NOT WORK
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, DisplayMessageActivity.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(DisplayMessageActivity.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());
    // ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000);
  }
  @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();
  }
Пример #18
0
  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());
  }
Пример #19
0
  private void notificar(String titulo, String mensaje, Class<?> actividad) {
    Uri sonido = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(titulo)
            .setContentText(mensaje)
            .setSound(sonido)
            .setAutoCancel(true);

    Intent resultIntent = new Intent(this, actividad);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(1, mBuilder.build());
  }
Пример #20
0
  private void fireSimpleDefaultPriorityNotification(String notificationTitle, String contentText) {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle(notificationTitle)
            .setContentText(contentText)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainSetupActivity.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(MainSetupActivity.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);

    // simpleDefaultPriorityNotificationID allows you to update the notification later on.
    mNotificationManager.notify(simpleDefaultPriorityNotificationID, mBuilder.build());
  }
Пример #21
0
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void notifyMe(String titulo, String message) {
    counter++;
    NotificationCompat.Builder mNotifyBuilder;
    NotificationManager mNotificationManager =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotifyBuilder =
        new NotificationCompat.Builder(this)
            .setContentTitle(titulo)
            .setContentText(message)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setDefaults(Notification.DEFAULT_SOUND)
            .setNumber(counter)
            .setAutoCancel(true);
    mNotifyBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));

    mNotificationManager.notify(NOTIFY_ME_ID, mNotifyBuilder.build());

    Intent intent = new Intent(this, HomeActivity.class);
    intent.addFlags(
        Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_NEW_TASK);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(HomeActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mNotifyBuilder.setContentIntent(resultPendingIntent);
    mNotificationManager.notify(NOTIFY_ME_ID, mNotifyBuilder.build());
  }
  private void sendNotification(String uniqueId) {
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
            .setContentTitle("New item found")
            .setContentText("An beacon of item " + uniqueId + " is nearby.")
            .setSmallIcon(R.drawable.ic_shopping_basket_24dp)
            .setAutoCancel(true);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack
    stackBuilder.addParentStack(DetailViewActivity.class);
    // Adds the Intent to the top of the stack
    Intent intent = new Intent(this, DetailViewActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    ItemSet itemSet = new ItemSet();
    itemSet.imageList.add(SpecifyViewActivity.setBtImage(uniqueId));
    intent.putExtra("itemSet", itemSet);
    intent.putExtra("name", (String) null);
    intent.putExtra("id", Integer.parseInt(uniqueId));
    intent.setAction(Long.toString(System.currentTimeMillis()));
    stackBuilder.addNextIntent(intent);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Integer.parseInt(uniqueId), builder.build());
  }
  private void createNotification(String title, String description, int tag) {
    NotificationManager notificationManager =
        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Intent intent = new Intent(this, NotificationActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("tag", counter);
    PendingIntent pIntent =
        PendingIntent.getActivity(this, counter, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    // Actions are just fake
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setContentTitle(title)
            .setContentText(description)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(pIntent);
    notificationBuilder.setContentIntent(pIntent);
    Notification notification = notificationBuilder.build();
    // Hide the notification after its selected
    // noti.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.DEFAULT_VIBRATE;
    notification.flags |= Notification.DEFAULT_SOUND;
    notification.flags |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(tag, notification);
  }
  public void showNotification(String msg) {
    Log.d("AlarmService", "Preparing to send notification...: " + msg);

    /** Setting Up Alarm* */
    alarmNotificationManager =
        (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent =
        PendingIntent.getActivity(
            getActivity(), 0, new Intent(getActivity(), AlertCallerFragmentActivity.class), 0);

    Uri sound =
        Uri.parse(
            "android.resource://" + getActivity().getPackageName() + "/" + R.raw.soundsmedication);
    /** Building Notifications* */
    NotificationCompat.Builder alamNotificationBuilder =
        new NotificationCompat.Builder(getActivity())
            .setContentTitle("Malaria Prevention")
            .setSmallIcon(R.drawable.appicon_themed)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setContentText(msg);

    alamNotificationBuilder.setSound(sound);

    alamNotificationBuilder.setContentIntent(contentIntent);
    alarmNotificationManager.notify(1, alamNotificationBuilder.build());
    Log.d("AlarmService", "Notification sent.");
  }
  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());
  }
  @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);
    }
  }
Пример #27
0
  private Notification getNotification() {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.launcher_icon)
            .setContentTitle("SleepMinder is active")
            .setContentText("Sleep well :)");

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, 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
    // 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);

    mBuilder.setProgress(0, 0, true);
    mBuilder.setCategory(NotificationCompat.CATEGORY_PROGRESS);

    mBuilder.setOngoing(true);

    PendingIntent stopTrackingIntent =
        PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.addAction(R.drawable.ic_action_stop, "Stop tracking", stopTrackingIntent);

    return mBuilder.build();
  }
Пример #28
0
  public void showNotification(Friend f) {
    Log.i(TAG, "notification");
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Tracing of \n" + f.getPseudo())
            .setContentText(f.getFirstName() + "," + f.getLastName());
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, GoogleMapActivity.class);

    f.setVisibleInMap(true);
    // resultIntent.putExtra("onePoint", f);
    // 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(GoogleMapActivity.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(0, mBuilder.build());
  }
Пример #29
0
  private void showEventNotification(int noteId, int icon, String title, String msg) {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(icon)
            .setContentTitle(title)
            .setContentText(msg)
            .setAutoCancel(true)
            .setDefaults(
                Notification.DEFAULT_LIGHTS
                    | Notification.DEFAULT_SOUND
                    | Notification.DEFAULT_VIBRATE);

    // Creates an explicit intent for an Activity in your app
    Intent intent = new Intent(this, ViewTransactionsActivity.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(ViewTransactionsActivity.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);
    mBuilder.setContentIntent(resultPendingIntent);

    mNM.notify(noteId, mBuilder.build());
  }
Пример #30
0
 @Override
 public void onCancel() {
   mGoogleApiClient.disconnect();
   String title = getString(R.string.app_name);
   // initialize the notification
   NotificationCompat.Builder mBuilder =
       new NotificationCompat.Builder(getApplicationContext())
           .setSmallIcon(R.mipmap.ic_launcher_logo)
           .setContentTitle(title)
           .setContentText(getString(R.string.alarm_cancelled))
           .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
           .setAutoCancel(true);
   Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
   PendingIntent resultPendingIntent =
       PendingIntent.getActivity(
           getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
   mBuilder.setContentIntent(resultPendingIntent);
   NotificationManager mNotificationManager =
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
   //  allows you to update the notification later on.
   if (!declined) {
     mNotificationManager.notify(AlarmNotifier.notificationID, mBuilder.build());
     String text = getString(R.string.alarm_cancelled);
     Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG);
     toast.show();
   }
   finish();
 }