How do I prevent Android taking a screenshot when my app goes to the background?

前端 未结 6 1174
说谎
说谎 2020-11-22 08:15

The app I\'m currently building has the requirement that the app has to prevent the OS to take a screenshot of the app when it\'s being pushed into the background for securi

6条回答
  •  终归单人心
    2020-11-22 08:40

    Be careful about using WindowManager.LayoutParams.FLAG_SECURE, on some devices (verified on Samsung Galaxy ACE, e.g. GT-S5830) this will make the view scrambled. Looks like a Samsung specific bug. I recommend the following:

    if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }
    

    This is what a scrambled screen looks like:

    Scrambled Screen Image

    This is working properly on ICS Samsung phones though, so I'm assuming problem is isolated to Gingerbread devices (or older).

提交回复
热议问题