Last active
November 26, 2018 07:21
-
-
Save AlonsoFloo/8cb84e0c074a068faa5af340ee52a39a to your computer and use it in GitHub Desktop.
Android default notification template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void createNewNotification(@NonNull Context context, @NonNull String channelId, int notificationId, @Nullable PendingIntent pendingIntent, @NonNull String longTitle, @NonNull String description) { | |
if (longTitle.isEmpty()) { | |
return; | |
} | |
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); | |
int icon = 0; | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
icon = R.drawable.ic_notification; | |
} else { | |
icon = R.mipmap.ic_launcher; | |
} | |
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId) | |
.setContentIntent(pendingIntent) | |
.setAutoCancel(true) | |
.setSmallIcon(icon) | |
.setContentTitle(longTitle) | |
.setContentText(description) | |
.setStyle(new NotificationCompat.BigTextStyle() | |
.bigText(description)) | |
.setTicker(longTitle) | |
.setSound(defaultSoundUri) | |
.setColor(ContextCompat.getColor(context, R.color.colorAccent)) | |
.setLights(ContextCompat.getColor(context, R.color.colorAccent), 600, 600) | |
.setCategory(NotificationCompat.CATEGORY_REMINDER) | |
.setDefaults(NotificationCompat.DEFAULT_VIBRATE) | |
.setPriority(NotificationCompat.PRIORITY_HIGH) | |
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL); | |
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | |
notificationManager.notify(notificationId, notificationBuilder.build()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment