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);
    }
  }
Пример #2
0
  public void createNotification(Context context, Bundle extras) {
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);

    Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

    PendingIntent contentIntent =
        PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(extras.getString("title"))
            .setTicker(extras.getString("title"))
            .setContentIntent(contentIntent);

    String message = extras.getString("message");
    if (message != null) {
      mBuilder.setContentText(message);
    } else {
      mBuilder.setContentText("<missing message content>");
    }

    String msgcnt = extras.getString("msgcnt");
    if (msgcnt != null) {
      mBuilder.setNumber(Integer.parseInt(msgcnt));
    }

    mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build());
  }
Пример #3
0
        @Override
        public void onClick(View v) {
          // TODO Auto-generated method stub
          NotificationCompat.Builder mBuilder =
              new NotificationCompat.Builder(context)
                  .setSmallIcon(R.drawable.notification_icon)
                  .setContentTitle("My notification")
                  .setContentText("Hello World! \n hello world!!");
          // Creates an explicit intent for an Activity in your app
          Intent resultIntent = new Intent(context, MainController.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(MainController.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) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
          // mId allows you to update the notification later on.
          mBuilder.setTicker("helo");
          mNotificationManager.notify(1, mBuilder.build());
          mBuilder.setNumber(1).setAutoCancel(true);
        }
 private void setNotificationCount(
     Context context, Bundle extras, NotificationCompat.Builder mBuilder) {
   int count = extractBadgeCount(extras);
   if (count >= 0) {
     Log.d(LOG_TAG, "count =[" + count + "]");
     mBuilder.setNumber(count);
   }
 }
 private void setNotificationCount(Bundle extras, NotificationCompat.Builder mBuilder) {
   String msgcnt = getString(extras, MSGCNT);
   if (msgcnt == null) {
     msgcnt = getString(extras, BADGE);
   }
   if (msgcnt != null) {
     mBuilder.setNumber(Integer.parseInt(msgcnt));
   }
 }
  /**
   * 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());
  }
  /**
   * 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());
  }
Пример #8
0
  @Override
  public void onLocationUpdate(Map<String, User> reply) {
    NotificationManager mNotificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder myBuilder = new NotificationUtil().prepareBuilder(mContext);
    myBuilder.setNumber(reply.size());
    // mId allows you to update the notification later on.
    mNotificationManager.notify(NotificationUtil.NOTIFICATION_ID, myBuilder.build());

    for (User user : reply.values()) {
      passiveLocationController.addProximityAlert(user);
    }
  }
Пример #9
0
 @Override
 public Builder setNumber(int number) {
   super.setNumber(number);
   return this;
 }
Пример #10
0
  public void createNotification(Context context, Bundle extras) {
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);

    Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

    PendingIntent contentIntent =
        PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    int defaults = Notification.DEFAULT_ALL;

    if (extras.getString("defaults") != null) {
      try {
        defaults = Integer.parseInt(extras.getString("defaults"));
      } catch (NumberFormatException e) {
      }
    }

    AssetManager am = context.getAssets();
    String sound = extras.getString("sound");
    Log.e(TAG, "Requested sound: " + sound);
    if (am != null && !sound.toLowerCase().equals("default")) {
      try {
        String target = "www/res/sounds/" + sound;
        Log.e(TAG, "target sound path: " + target);

        // added for support online build
        File file = new File(target);
        if (!file.exists()) {
          target = "www/sounds/" + sound;
          Log.e(TAG, "target new sound path: " + target);
        }

        // ur= Uri.fromFile(context.getFileStreamPath(target).getAbsoluteFile());
        AssetFileDescriptor afd = am.openFd(target);

        MediaPlayer player = new MediaPlayer();
        player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        player.prepare();
        player.start();

        defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;

      } catch (Exception e) {
        Log.e(TAG, "Exception: " + e.getMessage());
      }
    } else {
      Log.e(TAG, "AM is null");
    }

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(defaults)
            .setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(extras.getString("title"))
            .setTicker(extras.getString("title"))
            .setContentIntent(contentIntent)
            .setAutoCancel(true);

    String message = extras.getString("message");
    if (message != null) {
      mBuilder.setContentText(message);
    } else {
      mBuilder.setContentText("<missing message content>");
    }

    String msgcnt = extras.getString("msgcnt");
    if (msgcnt != null) {
      mBuilder.setNumber(Integer.parseInt(msgcnt));
    }

    int notId = 0;

    try {
      notId = Integer.parseInt(extras.getString("notId"));
    } catch (NumberFormatException e) {
      Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
    } catch (Exception e) {
      Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
    }

    mNotificationManager.notify((String) appName, notId, mBuilder.build());
  }
  public void createNotification(Context context, Bundle extras) {
    int notId = 0;

    try {
      notId = Integer.parseInt(extras.getString("notId"));
    } catch (NumberFormatException e) {
      Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
    } catch (Exception e) {
      Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
    }
    if (notId == 0) {
      // no notId passed, so assume we want to show all notifications, so make it a random number
      notId = new Random().nextInt(100000);
      Log.d(TAG, "Generated random notId: " + notId);
    } else {
      Log.d(TAG, "Received notId: " + notId);
    }

    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(context);

    Intent notificationIntent = new Intent(context, PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, notId, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    int defaults = Notification.DEFAULT_ALL;

    if (extras.getString("defaults") != null) {
      try {
        defaults = Integer.parseInt(extras.getString("defaults"));
      } catch (NumberFormatException ignore) {
      }
    }

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(defaults)
            .setSmallIcon(getSmallIcon(context, extras))
            .setWhen(System.currentTimeMillis())
            .setContentTitle(extras.getString("title"))
            .setTicker(extras.getString("title"))
            .setContentIntent(contentIntent)
            .setColor(getColor(extras))
            .setAutoCancel(true);

    String message = extras.getString("message");
    if (message != null) {
      mBuilder.setContentText(message);
    } else {
      mBuilder.setContentText("<missing message content>");
    }

    String msgcnt = extras.getString("msgcnt");
    if (msgcnt != null) {
      mBuilder.setNumber(Integer.parseInt(msgcnt));
    }

    String soundName = extras.getString("sound");
    if (soundName != null) {
      Resources r = context.getResources();
      int resourceId = r.getIdentifier(soundName, "raw", context.getPackageName());
      Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resourceId);
      mBuilder.setSound(soundUri);
      defaults &= ~Notification.DEFAULT_SOUND;
      mBuilder.setDefaults(defaults);
    }

    final Notification notification = mBuilder.build();
    final int largeIcon = getLargeIcon(context, extras);
    if (largeIcon > -1) {
      notification.contentView.setImageViewResource(android.R.id.icon, largeIcon);
    }

    mNotificationManager.notify(appName, notId, notification);
  }