Hide screen in 'Recent Apps List', but allow screenshots
Asked Answered
T

4

26

I mainly want to blank the screen in the recent apps list due to sensitive data being shown. For this, the solution is to use:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

but this also disallows screenshots, which is a problem.

Is there a way to show a blank screen (or a predefined image) in the recent apps list, while still allowing screenshots?

Trump answered 15/4, 2015 at 6:4 Comment(4)
I am not sure if this will work and I don't have a test environment available right now, but you might try making your sensitive fields invisible in onPause and restoring them onResumeDurkin
@RobbeRoels, that sounds good - I'll give that a tryTrump
@rajath did you find a solution for this that works not only for Android 8+, but for Android 6 and 7 as well?Perice
Does this answer your question? How do I prevent Android taking a screenshot when my app goes to the background?Embattled
L
0

I think what you need is:

android:excludeFromRecents="true"

put that in your android manifest inside your <activity>(activity you want to exclude from recents)</activity>

Lenient answered 15/4, 2015 at 6:8 Comment(3)
This completely removes the app from the recents list, which is not what I wantTrump
hmm... well you could maybe overlay your activity with one big black image, and make that one Visible in your onPause() and make it Gone in your onResume()Lenient
@Lenient that doesn't work, because the thumbnail is created before the onPause() method is calledGametophyte
D
23

I have tried this method and it's working. For making the screen blank in recent list and still allowing screen you can set the flag in onPause() and clear the flag in onResume().

@Override
protected void onPause() {
  super.onPause();
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,WindowManager.LayoutParams.FLAG_SECURE);
}

@Override
protected void onResume() {
    super.onResume();
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);     
}
Dekow answered 23/3, 2018 at 5:34 Comment(4)
This solution doesn't seem to work on Samsung devices. Any workarounds?Toshikotoss
Works great on Android 8,9,10 But for previous versions is not working.Typesetter
This doesn't seem to work on Pixel 3 and 4 on Android OS version 10. But works fine on Samsung running Android 10 (: .Toshikotoss
I tested on Huawei and Samsung devices, both with Android 10. On both devices this solution does not work unfortunately. Thumbnail in the recent apps list just stays like without the flag.Irmairme
S
1

If your Activity is showing sensitive data, for the security reason is better to don't allow user to make screenshots. If you are worry even about recent app screen, why you are not worry about screenshots on the same time? I think, that Android OS SecureFlag is designed to protect your data, and screenshots ability, just negates it's purpose.
If you anyway, want this ability, you can try to move all your sensitive data to separate activity with this flag. In that case, you will protect your sensitive data, and in other app's activities will have ability to make screenshots.

Schizomycete answered 15/4, 2015 at 6:30 Comment(1)
I fully agree with your reasoning. Unfortunately, that's the requirement for the app, and I need to see if it is at all possible.Trump
D
1

After doing some research I have found this to be impossible at this point.

The onCreateThumbnail seems to be the function you're looking for. Unfortunately this function seems to be unimplemented or at least not working.

As Ped7g pointed out: The onCreateThumbnail is "won't fix" since 2014.

It's also flagged deprecated for removal in the Android onCreateThumbnail reference page

This functionality will most likely never work.

Durkin answered 17/4, 2015 at 7:23 Comment(4)
The onCreateThumbnail is "won't fix" since 2014... I wouldn't count on this one to be working in near future.Bede
Which I also stated "Unfortunately this function seems to be unimplemented or at least not working."Durkin
"not working" IMO is not as strong as "deliberately decided by Google to stay in non-working state"... sadly. Sounds like nifty functionality, with only some mild abuse potential, but I don't understand Android OS API design decisions since the very start of 1.2, so no wonder they are going in directions I don't like (btw, thanks for your information, it was helpful for me, I was just trying to emphasize the real state of this thing, it's "dead", highly likely forever).Bede
Fair enough, thank you for your comment, I'll edit this in the answerDurkin
L
0

I think what you need is:

android:excludeFromRecents="true"

put that in your android manifest inside your <activity>(activity you want to exclude from recents)</activity>

Lenient answered 15/4, 2015 at 6:8 Comment(3)
This completely removes the app from the recents list, which is not what I wantTrump
hmm... well you could maybe overlay your activity with one big black image, and make that one Visible in your onPause() and make it Gone in your onResume()Lenient
@Lenient that doesn't work, because the thumbnail is created before the onPause() method is calledGametophyte

© 2022 - 2024 — McMap. All rights reserved.