The anti-recording function of Android and dialog is invalid, and the anti-recording function of the game is invalid.

1. Normally prohibit screen recording Call the following code in the onCreate() method of Activity, but on Xiaomi, OPPO and other devices, only screen capture can be prohibited, but screen recording cannot be prohibited.

 @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
    } 

2. If the above method fails, you can use the following method, which is also called in the Activity's onCreate() method.

  @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.flags = WindowManager.LayoutParams.FLAG_SECURE;
        getWindow().setAttributes(params);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
    }

3. The above attributes set by Android Dialog are invalid. You can add the following code in the onCreate() method of BaseDialog or the current Dialog, which is to set the screen recording prohibition attribute for the current dialog window separately.

 WindowManager.LayoutParams params = getDialog().getWindow().getAttributes();
 params.flags = WindowManager.LayoutParams.FLAG_SECURE;
 getDialog().getWindow().setAttributes(params);

4. To disable screen recording in the game, just turn on the security password mode of SurfaceView, but it will cause the screen recording to be prohibited throughout the game.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //一定要在父类onCreate方法之后调用
        if (getGLSurfaceView() != null) getGLSurfaceView().setSecure(true);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

    }
The getGLSurfaceView() method is to obtain the private variable in the parent class Cocos2dxActivity method, or change the parent class mGLSurfaceView variable from private to protected, then the above method can also be used

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mGLSurfaceView != null) mGLSurfaceView.setSecure(true);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
    }
5. If you can sometimes record the screen in the game, and sometimes you can’t record it, the fourth method is not enough, but Android’s prohibition of screen recording function does not take effect on the SurfaceView used in the game, then you can suspend it on the general layout An ImageView or TextView, do not set any content for it, and set it to be transparent, so that setting the prohibition of screen recording on the Actvity can take effect.

        Find the CocosdxActivity of the game, find the layout in it, he uses FrameLayout or ResizeLayout (inherited from FrameLayout), after he adds the SurfaceView page, add an ImageView.

// 修复SurfaceView处于顶层时WindowManager.LayoutParams.FLAG_SECURE失效的问题
        ImageView imageView = new ImageView(this);
        imageView.setAlpha(0.0f);
        mFrameLayout.addView(imageView);

 

Supongo que te gusta

Origin blog.csdn.net/zhao8856234/article/details/127784669
Recomendado
Clasificación