I think what you are looking for is one of the new features introduced by Lollipop (API21) in the notification system.
Using the new visibility property of the Notification in>, it is possible to tell the system when and how it should reveal the presence and contents of a notification.
There are 3 types of "visibility":
-
Secret (Notification.VISIBILITY_SECRET) - The notification is considered sensitive and is not shown in the "lock screen" . This is the default behavior (default).
-
Private (Notification.VISIBILITY_PRIVATE) - Notification is considered sensitive only with respect to content. It is displayed in the "lock screen" but the content of the message is replaced by "Contents hidden" .
-
Public (Notification.VISIBILITY_PUBLIC) - The notification is considered non-sensitive and the notification is fully displayed in the "lock screen"
The property can be "set" using Notification.Builder .
Notification notification = new Notification.Builder(this)
.setCategory(Notification.CATEGORY_MESSAGE)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(icon)
.setAutoCancel(true)
.setVisibility(Notification.VISIBILITY_PUBLIC).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(notification_id, notification );
Note : This property is only available from API21. Appcompat makes it accessible and can be used, but its effect is only felt on a device with Android 5 or higher.