Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide screen in 'Recent Apps List', but allow screenshots

Tags:

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?

like image 877
Rajath Avatar asked Apr 15 '15 06:04

Rajath


People also ask

How do I hide app previews on Android?

On Android, developers can prevent apps from being screenshotted by setting FLAG_SECURE. This has the intended side effect of also preventing app previews from being shown in the multitasking menu, as those previews are essentially screenshots of the app in their last used state.


4 Answers

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);     
}
like image 91
Vrushab Maitri Avatar answered Oct 10 '22 16:10

Vrushab Maitri


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>

like image 24
Strider Avatar answered Oct 10 '22 16:10

Strider


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.

like image 45
VadymVL Avatar answered Oct 10 '22 16:10

VadymVL


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.

like image 36
Robbe Roels Avatar answered Oct 10 '22 15:10

Robbe Roels