You must hide the contents of the program with Android "Screen Overview"

I am working on an Android application for the employer responsible for safety. He is concerned about the screenshot that appears on the Overview screen (as well as on the list of recent tasks), which skips confidential information and wants me to raise the program's screensavers before the system accepts this image. Unfortunately, I did not find a way to do this.

Things I tried:

  • Press the Show splash screen in onPause function. (No effect, even with bringToFront and setVisibility(View.VISIBLE) .)
  • Stick the screen saver in onCreate and use bringToFront in onPause . (Again, no effect.)
  • Call setVisible(false) in onPause . (It almost seems to work, as the screen flashes instantly to black when it switches from the program, but apparently it becomes the system again before the snapshot.)
  • Call setVisibility(View.INVISIBLE) on the top view item in onPause . (This seems to work, but the snapshot seems to have been taken before it takes effect.)

I am a moderately perfect Android developer, but I cannot help but feel that there is a simple solution that I am missing.

+7
source share
3 answers

Personally, I would go with FLAG_SECURE and just block the display of this stuff everywhere:

 public class FlagSecureTestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); setContentView(R.layout.main); } } 

However, IIRC, you can override onCreateThumbnail() to provide your own image for use on your recent to-do list. Please note that this could change from Android 5.0, as they have reworked this list of recent tasks, so be sure to check your code on your device or emulator 5.0.

+9
source

Instead of starting an action, you can consider launching an application task using ActivityManager.addAppTask(Activity, Intent, ActivityManager.TaskDescription, Bitmap) , with which the bitmap that you transmitted is used as a thumbnail on the browse / recent screen.

The document about this api is here , however it is only available in Lollipop.

+1
source

Here is a solution that allows you to hide the contents of the application by closing it with a splash screen when the application is placed in the background. This does not use the FLAG_SECURE technique, I just redefine the onPause and onResume methods of the screens and change the view to show the one that covers everything in the back.

First, I create the splash screen in a separate file in the form of relative markup with the name splash_screen_custom, I also assign the relative markup in the id customSplash file. Pay attention to the height adjustment, I encountered a problem when the buttons have a predefined height, therefore, setting this cover screen to a high height, it will cover any buttons (of course, you do not need this if you do not close the buttons).

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/customSplash" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/backgroundColor" android:elevation="5dp" > <ImageView android:id="@+id/imageView" android:layout_width="202dp" android:layout_height="157dp" android:layout_centerInParent="true" app:srcCompat="@drawable/yourImage" /> </RelativeLayout> 

In this example, my screen that I am trying to cover is a relative layout, so I can simply add and remove my splash screen to it using the addView and removeView view methods that I am trying to cover.

 override fun onPause() { var parentView = findViewById<RelativeLayout>(R.id.parentView) var splashScreen = layoutInflater.inflate(R.layout.splash_screen_custom, null) parentView.addView(splashScreen, parentView.width, parentView.height) super.onPause() } override fun onResume() { var parentView = findViewById<RelativeLayout>(R.id.parentView) parentView.removeView(findViewById<RelativeLayout>(R.id.customSplash)) super.onResume() } 
+1
source

Source: https://habr.com/ru/post/979080/


All Articles