Guest User

Untitled

a guest
Oct 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. void showNotification(Context context, int id, SharedPreferences preferences, String notificationMessage, String link, Notification.Type type) {
  2. if (SugarRecord.count(Notification.class, "notification_id = ?", new String[] {id+""}) > 0)
  3. return;
  4. if (!SettingsNotificationActivity.isNotificationAllowed(preferences)) return;
  5.  
  6. NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  7.  
  8. PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
  9. new Intent("com.kbl.kbl.PUSH").putExtra(SplashActivity.NOTIFICATION_ID, id), 0);
  10.  
  11. NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
  12. .setSmallIcon(R.mipmap.ic_launcher)
  13. .setContentTitle(context.getString(R.string.notification_title))
  14. .setPriority(NotificationCompat.PRIORITY_HIGH)
  15. .setCategory(NotificationCompat.CATEGORY_MESSAGE)
  16. .setAutoCancel(true);
  17.  
  18. if (SettingsNotificationActivity.isSoundAllowed(preferences)) {
  19. String notificationSoundUri = UserData.getNotificationSoundUri(preferences);
  20. Uri uri = notificationSoundUri.isEmpty() ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(notificationSoundUri);
  21.  
  22. notificationBuilder.setSound(uri);
  23. }
  24.  
  25. notificationBuilder.setContentText(notificationMessage);
  26. notificationBuilder.setContentIntent(pendingIntent);
  27.  
  28. new Notification(notificationMessage, id, link, type).save();
  29.  
  30. android.app.Notification notification = notificationBuilder.build();
  31. if (SettingsNotificationActivity.isVibrationAllowed(preferences)) {
  32. notification.defaults |= NotificationCompat.DEFAULT_VIBRATE;
  33. }
  34.  
  35. notificationManager.notify(id, notification);
  36. }
Add Comment
Please, Sign In to add comment