Skip to content

Instantly share code, notes, and snippets.

@jgilfelt
Created November 28, 2014 10:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgilfelt/8105b5ca07776a4359c2 to your computer and use it in GitHub Desktop.
Save jgilfelt/8105b5ca07776a4359c2 to your computer and use it in GitHub Desktop.
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