How to disable screen capture in Android fragment?

后端 未结 2 1641
梦如初夏
梦如初夏 2020-12-18 02:08

Is it possible to disable screen capture from a fragment? I know the below works for an Activity class

onCreate(Bundle savedInstanceState) {
    super.onCrea         


        
2条回答
  •  天涯浪人
    2020-12-18 02:36

    The below code worked for me.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getActivity().getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
        Window window = getActivity().getWindow();
        WindowManager wm = getActivity().getWindowManager();
        wm.removeViewImmediate(window.getDecorView());
        wm.addView(window.getDecorView(), window.getAttributes());
    
    }
    

提交回复
热议问题