How to prevent two-factor code being exposed on lock screen in messages notification? On Lollipop, the text message notification on the lock screen includes some of the content of the text message. For two-factor code text messages, this will display the two factor code to anyone holding the phone even if they cannot unlock it. This seems like a security issue. 

There seems to be a setting that more carefully hides the contents of notifications on the lock screen but that makes many of the other notifications useless it is hides data which I feel is useful and harmless to share.

I guess the options are:


Hide the content and put up with the inconvenience on other apps in the name of security.
Disable notifications from the messages app but then I have no way to know if there are new messages without manually checking.
Hide the content and petition other app makers to not respect that setting if the content isn't sensitive. Though I can easily think of examples that I might not consider sensitive but others might.


Are there other options available here? I'd love it if the messages app had a setting to control that behaviour. I'd be happy with the text message sender being displayed instead of the content.
I would say the first notification in first image would serve as a good replacement for the first notification in second image. 

(Click an image to enlarge it)




Given that an SMS usually contains information considered private in nature, I would suggest you setup an automation task which would remove the notification created by your default messaging app but instead place a new notification with sender's address only. Opening that new notification would open the default messaging app and if needed, perhaps the particular thread as well.

Following is a successful demonstration performed using MacroDroid:

MacroDroid defines a set of trigger(s), action(s) and constraint(s) as a macro. You would be needing two macros here. 

Macro 1:


Trigger: Empty Trigger
Action: Launch Application &rarr; select your messaging app
Constraint: ignore
Name: Launch messaging app


Macro 2:


Trigger:  Notification &rarr; Notification Received:


From: choose your default/preferred messaging app
Text Content: you can play with this but I suggest you begin with blacklisting any notification from messaging app. For that, select Any to trigger for any notification. 

Action: 


Clear Notifications &rarr; Select Application(s) &rarr; select your messaging app
Display Notification:


Icon: change as appropriate
In the first text field write: [not_title]

[not_title] corresponds to Notification Title (the title of the notification which acted as the trigger). 

You may be interested in dealing with further information from the notification. For that, tap the button next to the text field and see the information for yourself.
In the second text field write anything that you need. As an example, you can write: Double tap to open the message
Tick Invoke macro when pressed and select your first macro i.e. Launch messaging app


Constraint: Device Locked/Unlocked &rarr; Locked
Name: as appropriate to you 


This is how the said macros works: whenever any notification from your selected messaging app would show up when the device is locked, the notification would be immediately removed and a new notification from MacroDroid would be generated with the same title and your custom text. If you single/double tap the notification your selected messaging app would be launched. 

(Click an image to enlarge it; the two macros I created)




It is possible to easily make a similar automation task using Automate app.