我想录制手机的屏幕。当我在API 23上测试它时工作正常但是当我在api 22上测试代码时它无法获得表面,但代码在android marshmallow上运行良好。
private VirtualDisplay createVirtualDisplay()
{
return mMediaProjection.createVirtualDisplay("MainActivity",
DISPLAY_WIDTH, DISPLAY_HEIGHT, mScreenDensity,
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mMediaRecorder.getSurface(), null /*Callbacks*/, null
/*Handler*/);
}
在
上收到错误的屏幕截图mMediaRecorder.getSurface()
答案 0 :(得分:0)
我面临着同样的问题。授予运行时权限。
if (ContextCompat.checkSelfPermission(TestInstructions.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ ContextCompat.checkSelfPermission(TestInstructions.this,
Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(TestInstructions.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
|| ActivityCompat.shouldShowRequestPermissionRationale(TestInstructions.this,
Manifest.permission.RECORD_AUDIO)) {
Snackbar.make(relativeLayout, R.string.label_permissions, Snackbar.LENGTH_INDEFINITE)
.setAction("ENABLE", new View.OnClickListener() {
@Override
public void onClick(View v) {
ActivityCompat.requestPermissions(TestInstructions.this, new String[] {
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO },
REQUEST_PERMISSIONS);
}
}).show();
} else {
ActivityCompat.requestPermissions(TestInstructions.this,
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO },
REQUEST_PERMISSIONS);
}
}
它将解决您的问题。