Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void showNotification(Context context, int id, SharedPreferences preferences, String notificationMessage, String link, Notification.Type type) {
- if (SugarRecord.count(Notification.class, "notification_id = ?", new String[] {id+""}) > 0)
- return;
- if (!SettingsNotificationActivity.isNotificationAllowed(preferences)) return;
- NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
- new Intent("com.kbl.kbl.PUSH").putExtra(SplashActivity.NOTIFICATION_ID, id), 0);
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
- .setSmallIcon(R.mipmap.ic_launcher)
- .setContentTitle(context.getString(R.string.notification_title))
- .setPriority(NotificationCompat.PRIORITY_HIGH)
- .setCategory(NotificationCompat.CATEGORY_MESSAGE)
- .setAutoCancel(true);
- if (SettingsNotificationActivity.isSoundAllowed(preferences)) {
- String notificationSoundUri = UserData.getNotificationSoundUri(preferences);
- Uri uri = notificationSoundUri.isEmpty() ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(notificationSoundUri);
- notificationBuilder.setSound(uri);
- }
- notificationBuilder.setContentText(notificationMessage);
- notificationBuilder.setContentIntent(pendingIntent);
- new Notification(notificationMessage, id, link, type).save();
- android.app.Notification notification = notificationBuilder.build();
- if (SettingsNotificationActivity.isVibrationAllowed(preferences)) {
- notification.defaults |= NotificationCompat.DEFAULT_VIBRATE;
- }
- notificationManager.notify(id, notification);
- }
Add Comment
Please, Sign In to add comment