コード例 #1
0
ファイル: ChatListFragment.java プロジェクト: robinvz/TeamC
    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);
    }
コード例 #2
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());
        }
    }
  }
コード例 #3
0
  public static void showNotification(Context context) {

    //  NotificationCompat.Builder mBuilder

    Notification.Builder mBuilder =
        new Notification.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("GPS HACK")
            .setOngoing(true)
            .setContentText("Active");

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, Home.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(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(Home.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);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
  }
コード例 #4
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();
  }
コード例 #5
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();
  }
コード例 #7
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());
  }
コード例 #8
0
  /**
   * The '@JavascriptInterface is required to make the method accessible from the Javascript layer
   *
   * <p>The code in this method is based on the documentation here:
   *
   * <p>http://developer.android.com/training/notify-user/build-notification.html
   *
   * @param message The message displayed in the notification
   */
  @JavascriptInterface
  public void showNotification(String message) {
    Log.wtf(TAG, "showNotification");
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle(mContext.getString(R.string.notification_title))
            .setContentText(message)
            .setAutoCancel(true);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(mContext, MainActivity.class);
    resultIntent.putExtra(MainFragment.EXTRA_FROM_NOTIFICATION, 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
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    // 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) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(-1, mBuilder.build());
  }
コード例 #9
0
ファイル: WalletService.java プロジェクト: ksedgwic/Wallet32
  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());
  }
コード例 #10
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());
  }
コード例 #11
0
  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());
  }
コード例 #12
0
  public void setIntent(Intent intent) {
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntent(intent);

    PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
  }
  /**
   * Create and show a notification containing the conversations name where the new conversation
   * message was posted.
   */
  private void sendNewConversationMessageNotification(int groupId, int conversationId) {
    Intent intent;
    boolean loggedIn = Util.getInstance(this).getLoggedInModerator() != null;
    if (loggedIn) {
      // User is logged in as local moderator.
      intent = new Intent(this, ModeratorMainActivity.class);
    } else {
      // User isn't logged in.
      intent = new Intent(this, GroupActivity.class);
    }
    intent.putExtra("groupId", groupId);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // Create a PendingIntent containing the entire back stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    if (loggedIn) {
      stackBuilder.addParentStack(ModeratorMainActivity.class);
    } else {
      stackBuilder.addParentStack(GroupActivity.class);
    }
    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(groupId, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set group icon as large icon.
    Conversation conversation =
        new GroupDatabaseManager(getApplicationContext()).getConversation(conversationId);
    Bitmap bitmap =
        BitmapFactory.decodeResource(
            getResources(),
            GroupController.getConversationIcon(conversation, getApplicationContext()));
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notification_icon_1)
            .setColor(ContextCompat.getColor(this, R.color.uni_main_primary))
            .setLargeIcon(bitmap)
            .setContentTitle(
                String.format(
                    getString(R.string.push_message_conversation), conversation.getTitle()))
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    if (conversation.getNumberOfUnreadConversationMessages() > 1) {
      notificationBuilder.setContentText(
          getString(R.string.push_message_new_conversation_messages));
      notificationBuilder.setNumber(conversation.getNumberOfUnreadConversationMessages());
    } else {
      notificationBuilder.setContentText(getString(R.string.push_message_new_conversation_message));
    }

    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(5, notificationBuilder.build());
  }
コード例 #14
0
  public void setActivity(Class activity) {
    Intent intent = new Intent(context, activity);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(activity);
    stackBuilder.addNextIntent(intent);

    PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
  }
コード例 #15
0
  private NotificationCompat.Builder buildNotification(int notif_id) {
    Builder builder = new NotificationCompat.Builder(this).setWhen(System.currentTimeMillis());
    // The default notification send the user to the waiting list
    Intent intentContent = new Intent(this, WaitListActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(WaitListActivity.class);
    stackBuilder.addNextIntent(intentContent);
    PendingIntent pendingContent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingContent);

    switch (notif_id) {
      case NOTIFICATION_SEND:
        builder
            .setSmallIcon(android.R.drawable.stat_sys_upload)
            .setTicker(getString(R.string.txt_sending))
            .setContentTitle(getString(R.string.txt_sending));
        return builder;
      case NOTIFICATION_SEND_LATER:
        builder
            .setAutoCancel(true)
            .setSmallIcon(android.R.drawable.stat_notify_error)
            .setTicker(getString(R.string.txt_error_no_connection))
            .setContentTitle(getString(R.string.txt_error_no_connection))
            .setContentText(getString(R.string.txt_error_try_again));
        return builder;
      case NOTIFICATION_ERROR:
        builder
            .setAutoCancel(true)
            .setSmallIcon(android.R.drawable.stat_notify_error)
            .setTicker(getString(R.string.txt_error_sending))
            .setContentTitle(getString(R.string.txt_error_sending))
            .setContentText(getString(R.string.txt_error_try_again));
        return builder;
      case NOTIFICATION_NEED_AUTHORIZE:
        // When authorization is need, send the user to authorization
        // process
        intentContent.setClass(this, MainActivity.class);
        intentContent.setAction(Utils.ACTION_AUTHENTICATE);
        intentContent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingAuthorize =
            PendingIntent.getActivity(this, 0, intentContent, PendingIntent.FLAG_CANCEL_CURRENT);
        builder
            .setContentIntent(pendingAuthorize)
            .setAutoCancel(true)
            .setSmallIcon(android.R.drawable.stat_notify_error)
            .setTicker(getString(R.string.txt_error_sending))
            .setContentTitle(getString(R.string.txt_error_sending))
            .setContentText(getString(R.string.txt_need_authorize));
        return builder;

      default:
        return null;
    }
  }
  /**
   * Create and show a simple notification containing the channels name where the new announcement
   * was posted.
   */
  private void sendAnnouncementNotification(int channelId) {
    ChannelDatabaseManager channelDBM = new ChannelDatabaseManager(this);
    Channel channel = channelDBM.getChannel(channelId);
    int numberOfAnnouncements = channelDBM.getNumberOfUnreadAnnouncements(channelId);

    Intent intent;
    boolean loggedIn = Util.getInstance(this).getLoggedInModerator() != null;
    if (loggedIn) {
      // User is logged in as local moderator.
      intent = new Intent(this, ModeratorChannelActivity.class);
    } else {
      // User isn't logged in.
      intent = new Intent(this, ChannelActivity.class);
    }
    intent.putExtra("channelId", channelId);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // Create a PendingIntent containing the entire back stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    if (loggedIn) {
      stackBuilder.addParentStack(ModeratorChannelActivity.class);
    } else {
      stackBuilder.addParentStack(ChannelActivity.class);
    }
    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(channelId, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set channel icon as large icon.
    Bitmap bitmap =
        BitmapFactory.decodeResource(getResources(), ChannelController.getChannelIcon(channel));
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notification_icon_1)
            .setColor(ContextCompat.getColor(this, R.color.uni_main_primary))
            .setLargeIcon(bitmap)
            .setContentTitle(channel.getName())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    if (numberOfAnnouncements > 1) {
      notificationBuilder.setContentText(getString(R.string.push_message_new_announcements));
      notificationBuilder.setNumber(numberOfAnnouncements);
    } else {
      notificationBuilder.setContentText(getString(R.string.push_message_new_announcement));
    }

    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, notificationBuilder.build());
  }
コード例 #17
0
  private PendingIntent buildNotificationIntent() {
    Intent intent = new Intent(App.mApp, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(App.NOTIFICATION_ID, mId);
    intent.setData(Uri.parse("ClemetineDownload" + mId));

    // Create a TaskStack, so the app navigates correctly backwards
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(App.mApp);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
  }
  /*
   * Build the RemoteViews for the notification. We also need to add the appropriate "back stack"
   * so when user goes into the CastPlayerActivity, she can have a meaningful "back" experience.
   */
  private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying)
      throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
    Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = new Intent(this, mTargetActivity);

    contentIntent.putExtra("media", mediaWrapper);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(mTargetActivity);

    stackBuilder.addNextIntent(contentIntent);
    if (stackBuilder.getIntentCount() > 1) {
      stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
    }

    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT);

    MediaMetadata mm = info.getMetadata();

    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification);
    if (mIsIcsOrAbove) {
      addPendingIntents(rv, isPlaying, info);
    }
    if (null != bitmap) {
      rv.setImageViewBitmap(R.id.iconView, bitmap);
    } else {
      bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_album_art);
      rv.setImageViewBitmap(R.id.iconView, bitmap);
    }
    rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE));
    String castingTo =
        getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName());
    rv.setTextViewText(R.id.subTitleView, castingTo);
    mNotification =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_action_notification)
            .setContentIntent(resultPendingIntent)
            .setContent(rv)
            .setAutoCancel(false)
            .setOngoing(true)
            .build();

    // to get around a bug in GB version, we add the following line
    // see https://code.google.com/p/android/issues/detail?id=30495
    mNotification.contentView = rv;

    return rv;
  }
コード例 #19
0
ファイル: Notifier.java プロジェクト: sazoo/TweetLanes
  public static void notify(
      String title,
      String text,
      String bigText,
      Boolean autoCancel,
      int id,
      String accountKey,
      long postId,
      Context context) {
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setTicker(text)
            .setSmallIcon(R.drawable.notification_default)
            .setAutoCancel(autoCancel)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(title)
            .setContentText(text)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));

    Uri ringtone = AppSettings.get().getRingtoneUri();
    if (ringtone != null) {
      builder.setSound(ringtone);
    }

    Intent resultIntent = new Intent(context, HomeActivity.class);
    resultIntent.putExtra("account_key", accountKey);
    resultIntent.putExtra("post_id", postId);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(HomeActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    int requestCode = (int) (Math.random() * Integer.MAX_VALUE);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(resultPendingIntent);

    Intent deleteIntent = new Intent(context, DeleteNotificationsReceiver.class);
    deleteIntent.putExtra("account_key", accountKey);
    deleteIntent.putExtra("post_id", postId);
    requestCode = (int) (Math.random() * Integer.MAX_VALUE);
    PendingIntent deletePendingIntent =
        PendingIntent.getBroadcast(context, requestCode, deleteIntent, 0);

    builder.setDeleteIntent(deletePendingIntent);

    saveLastNotificationDisplayed(context, accountKey, postId);

    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(id, builder.build());
  }
コード例 #20
0
  private Notification notificacion() {
    NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);

    nBuilder.setSmallIcon(R.drawable.ic_launcher);
    nBuilder.setContentTitle("App Services");
    nBuilder.setContentText("Servicio Iniciado");

    Intent intent = new Intent(this, MenuPrincipal.class);

    TaskStackBuilder tStack = TaskStackBuilder.create(this);
    tStack.addNextIntent(intent);

    PendingIntent pIntent = tStack.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    nBuilder.setContentIntent(pIntent);

    return nBuilder.build();
  }
コード例 #21
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TaskStackBuilder builder = TaskStackBuilder.create(this);
    Intent proxyIntent = getIntent();
    if (!proxyIntent.hasExtra(EXTRA_INTENTS)) {
      finish();
      return;
    }

    for (Parcelable parcelable : proxyIntent.getParcelableArrayExtra(EXTRA_INTENTS)) {
      builder.addNextIntent((Intent) parcelable);
    }

    builder.startActivities();
    finish();
  }
コード例 #22
0
  /**
   * Hace visibles las notificaciones
   *
   * @param mensajes Mensajes a notificar
   */
  public void mostrarNotificacion(LinkedList<Mensaje> mensajes) {

    String textoNotificacionAuxiliar = "";
    for (int i = 0; i < mensajes.size(); i++) {
      textoNotificacionAuxiliar +=
          mensajes.get(i).getUsuario() + ": " + mensajes.get(i).getMensaje() + "\n";
    }

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

    if (mensajes.size() == 0) {
      mNotificationManager.cancel(mId);
      return;
    }

    if ((textoNotificacion.compareTo(textoNotificacionAuxiliar) == 0)) {
      return;
    }

    textoNotificacion = textoNotificacionAuxiliar;

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.not)
            .setContentTitle(getString(R.string.nuevos_mensajes))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(textoNotificacion));
    // .setSound(alarmSound);
    mBuilder.setSound(alarmSound);

    Intent resultIntent = new Intent(this, ListaDeConversacionesActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(ListaDeConversacionesActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
  }
コード例 #23
0
  // override the onPushOpen() method to open "ViewBloodRequestActivity" instead of app's launcher
  // activity when user taps on a Notification
  @Override
  protected void onPushOpen(Context context, Intent intent) {

    // since we override onPushOpen() method, we need to track our app's push open event manually
    ParseAnalytics.trackAppOpenedInBackground(intent);

    String targetActivity = null;

    // get the value of key "target" from the JSON data received in Parse Push notification
    try {
      JSONObject pushData = getJSONDataFromIntent(intent);
      targetActivity = pushData.getString("target");
    } catch (JSONException e) {
      Log.e(TAG, "Unexpected JSONException when receiving push data: ", e);
    }

    // get the launcher activity class for the app from ParsePushBroadcastReceiver's getActivity()
    // method
    Class<? extends Activity> cls = getActivity(context, intent);

    Intent activityIntent;
    if (targetActivity != null && !targetActivity.isEmpty()) {
      // send an explicit intent to open ViewBloodRequestActivity on tapping a push notification
      activityIntent = new Intent(context, ViewBloodRequestActivity.class);
      Log.d("notttt - ", "entering if");
    } else {
      // open the launcher activity of the app
      activityIntent = new Intent(context, cls);
      Log.d("notttt - ", "entering else");
    }

    if (Build.VERSION.SDK_INT >= 16) {
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
      stackBuilder.addParentStack(cls);
      stackBuilder.addNextIntent(activityIntent);
      stackBuilder.startActivities();
    } else {
      activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      context.startActivity(activityIntent);
    }
  }
  /**
   * Posts a notification in the notification bar when a transition is detected. If the user clicks
   * the notification, control goes to the MainActivity.
   */
  private void sendNotification(String notificationDetails) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

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

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

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

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

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

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

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

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

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
  }
コード例 #25
0
 private void handleActionNotification() {
   NotificationCompat.Builder builder =
       new NotificationCompat.Builder(this)
           .setSmallIcon(R.drawable.ic_action_device_access_bluetooth_searching)
           .setContentTitle("Bluetooth Circles")
           .setContentText("Click here to view connected devices");
   // Creates an explicit intent for an Activity in your app
   Intent resultIntent = new Intent(this, MainActivity.class);
   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);
   builder.setContentIntent(resultPendingIntent);
   NotificationManager mNotificationManager =
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
   // mId allows you to update the notification later on.
   mNotificationManager.notify(1, builder.build());
 }
コード例 #26
0
  // Put the message into a notification and post it.
  private void sendNotification(String msg, String enlace, String titulo, String imagen) {
    builder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Mama Huggies")
            .setContentText(msg);
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra("enlace", enlace);
    resultIntent.putExtra("titulo", titulo);
    resultIntent.putExtra("imagen", imagen);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFICATION_ID, builder.build());
  }
コード例 #27
0
ファイル: Common.java プロジェクト: avi-kr/budly-customer
  public static void notify(Context context, Intent intent, String msg) {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("My budly!")
            .setContentText(msg);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    if (intent != null) {
      stackBuilder.addNextIntent(intent);
    }
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification n = mBuilder.build();
    // n.defaults |= Notification.DEFAULT_SOUND;
    n.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(0x12345678, n);
  }
コード例 #28
0
  /**
   * Notification system that is used for this app. All we need to do is call this function when we
   * need to trigger a notification.
   */
  private void notification(long time) {
    final int finalseconds = (int) Math.ceil(time / 1000 / 60);
    final String contentText;

    if (finalseconds > 0) {
      contentText = "ISS is about " + finalseconds + " minutes away!";
    } else {
      contentText = "ISS is right above you!";
    }

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.iss_2011);
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setAutoCancel(true)
            .setOnlyAlertOnce(true)
            .setOngoing(false)
            .setContentTitle("ISS Tracker")
            .setContentText(contentText)
            .setSmallIcon(R.drawable.iss_2011)
            .setLargeIcon(icon)
            .setSound(soundUri)
            .setWhen(System.currentTimeMillis());

    Intent resultIntent = new Intent(context, Locations.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(Locations.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(NOTIFICATION_ID, mBuilder.build());
  }
コード例 #29
0
ファイル: Uploader.java プロジェクト: tom2320x/list
  public void startUploadNotification(int notificationID, String contentText) {
    mBuilder = new NotificationCompat.Builder(mContext);
    mBuilder
        .setContentTitle(mContext.getResources().getString(R.string.app_name_short))
        .setContentText(contentText)
        .setColor(mContext.getResources().getColor(R.color.colorSecondary))
        .setSmallIcon(R.drawable.ic_party_mode_white_24dp);

    Intent resultIntent = new Intent(mContext, MainActivity.class);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    android.support.v4.app.TaskStackBuilder stackBuilder =
        android.support.v4.app.TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(StartActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(notificationID, mBuilder.build());
  }
  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());
  }