prevent screen capture in Android apps

后端 未结 2 1563
离开以前
离开以前 2020-12-14 21:51

I was wondering if there is a way to detect through some \"onXXXXX\" call-back method or received broadcast if some other process is about to take a screen-shot of my app\'

2条回答
  •  余生分开走
    2020-12-14 22:07

    This worked for me on a Samsung Tab 2 7"

    Using the following approach, to simply add the FLAG_SECURE to the Window Flags

    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);
      }
    }
    

    with the caveat that you may need to change

    LayoutParams
    

    to

    WindowManager.LayoutParams
    

提交回复
热议问题