Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Notification whose content is partially redacted on API 21 secure lockscreens
private Notification buildNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setCategory(NotificationCompat.CATEGORY_EVENT)
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) // default
.setContentTitle(title)
.setContentText(shortText)
.setStyle(new NotificationCompat.BigTextStyle().bigText(fullText))
.setSmallIcon(R.drawable.ic_stat_notification)
.setColor(context.getResources().getColor(R.color.my_color))
.setContentIntent(intent);
// show all the above in public contexts
builder.setPublicVersion(builder.build());
// only show actions when unlocked
builder.addAction(R.drawable.ic_action, context.getString(R.string.action), actionIntent);
return builder.build();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.