Android virtual display release does not remove display

跟風遠走 提交于 2019-12-11 13:25:00

问题


I am using android Virtual Display along with Projection Manager At certain time, the projection need to be stopped, hence the following actions are taken

@Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        mMediaProjection.stop();
        Log.e(TAG, "mMediaProjection.stopped ");
        mVirtualDisplay.release();
        Log.e(TAG, "virtual display.released ");
    }

The surfaceDestroyed is related to the surface which backs the Virtual Display.

When it is the time to start Media Projection again, if available displays are iterated, the previously created virtual display still listed as one of available displays

DisplayManager disp = (DisplayManager) getSystemService(DISPLAY_SERVICE);
        Display[] allDisplays = disp.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
        Log.e(TAG+"-Display", "Display Count  "+allDisplays.length);
        for(Display dl : allDisplays){
            Log.e(TAG+"-Display", "Display name " + dl.getName()+" Display id "+dl.getDisplayId());
        }

How to properly handle Virtual display creation and removal ?

Note :

Following is the snippet of media projection and virtual display setup

mMediaProjection = mMediaProjectionManager.getMediaProjection(mResultCode, mResultData);
mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture",
                mSurfaceView.getWidth(), mSurfaceView.getHeight(), mScreenDensity,
                 DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR |DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION,
                mSurface, null, null);

来源:https://stackoverflow.com/questions/35718862/android-virtual-display-release-does-not-remove-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!