在Android系统中,如果需要进行屏幕录制,系统会提示用户是否允许录制屏幕。如果需要去掉这个提示,可以通过代码来实现。具体的解决方法如下:
private MediaProjectionManager mMediaProjectionManager;
private MediaProjection mMediaProjection;
private int mScreenDensity;
mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
mMediaProjection = mMediaProjectionManager.getMediaProjection(resultCode, data);
mScreenDensity = getResources().getDisplayMetrics().densityDpi;
private static final int DISPLAY_WIDTH = 720;
private static final int DISPLAY_HEIGHT = 1280;
private VirtualDisplay mVirtualDisplay;
private MediaRecorder mMediaRecorder;
mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture",
DISPLAY_WIDTH, DISPLAY_HEIGHT, mScreenDensity,
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mMediaRecorder.getSurface(), null /*Callbacks*/, null /*Handler*/);
mMediaRecorder.start();
通过以上代码可以实现在Android系统中进行录屏功能,不再弹出提示窗口。