授予权限后如何录制屏幕

tpgth1q7  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(246)

当显示应用程序时,将显示权限窗口以显示录制屏幕,并且当按下某个按钮时,录制停止,并且可以看到。之后,屏幕应自动记录再次无需再次请求权限,但权限窗口继续请求权限,尽管权限刚刚授予。这是我的密码。

private void screenRecordingRequestCodeRequest() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
        Intent intent = mediaProjectionManager.createScreenCaptureIntent();
        startActivityForResult(intent, SCREEN_RECORDING_REQUEST_CODE);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (requestCode == SCREEN_RECORDING_REQUEST_CODE) {
            Intent intent = ScreenRecordingService.newIntent(this, resultCode, data);
            boolean isServiceRunning = Utils.isServiceRunning(this, ScreenRecordingService.class);
            boolean isFinishCode = (resultCode == 0);
            if ((isServiceRunning && isFinishCode) || (!isServiceRunning && !isFinishCode)) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    startForegroundService(intent);
                } else {
                    startService(intent);
                }
            }
        }
    }
    finish();
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题