Пример #1
0
 // Playing notification sound
 public void playNotificationSound() {
   try {
     Uri alarmSound =
         Uri.parse(
             ContentResolver.SCHEME_ANDROID_RESOURCE
                 + "://"
                 + IsmartApp.getInstance().getApplicationContext().getPackageName()
                 + "/raw/notification");
     Ringtone r =
         RingtoneManager.getRingtone(IsmartApp.getInstance().getApplicationContext(), alarmSound);
     r.play();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #2
0
  private void showSmallNotification(
      NotificationCompat.Builder mBuilder,
      int icon,
      String title,
      String message,
      String timeStamp,
      PendingIntent resultPendingIntent,
      Uri alarmSound) {

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

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

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

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

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

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

    NotificationManager notificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Config.NOTIFICATION_ID, notification);
  }
Пример #3
0
 // Clears notification tray messages
 public static void clearNotifications() {
   NotificationManager notificationManager =
       (NotificationManager)
           IsmartApp.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
   notificationManager.cancelAll();
 }