[英]onActivityResult always got -1 as resultcode
I try to use MediaProjectionManager
to capture a screenshot. 我尝试使用
MediaProjectionManager
捕获屏幕截图。 The first step I take is typing following lines of code: 我要做的第一步是键入以下代码行:
MediaProjectionManager projectionManager = (MediaProjectionManager)this.getContext().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(projectionManager.createScreenCaptureIntent(), 1);
Then I expect to get responded with the onActivityResult(int requestCode, int resultCode, Intent data)
function. 然后,我希望使用
onActivityResult(int requestCode, int resultCode, Intent data)
函数进行响应。 However I find that the resultCode
is always -1 and the data always contains null uri and null mData. 但是,我发现
resultCode
始终为-1,并且数据始终包含null uri和null mData。 Its like there is no image content passed to onActivityResult
. 就像没有图像内容传递给
onActivityResult
。
Does anyone know what caused this issue or how to retrieve the screenshot from the data? 有谁知道是什么引起了这个问题,或者如何从数据中检索屏幕截图?
Any help is much appreciated! 任何帮助深表感谢!
Just take a look to the Activity.RESULT_OK. 只需查看Activity.RESULT_OK。
public static final int RESULT_OK = -1;
So if you get a -1 in your resultCode you're good. 因此,如果您的resultCode中为-1,则表示您很好。
Next after reading the MediaProjectionManager documentation 阅读MediaProjectionManager文档后的下一步
I read that you need to call getMediaProjection. 我读到您需要调用getMediaProjection。 Try to call getMediaProjection method in your onActivityResult and give it the resultCode and resultData.
尝试在onActivityResult中调用getMediaProjection方法,并为其提供resultCode和resultData。
To get a basic sample, look this code => MediaProjectionManager use 要获得基本示例,请查看以下代码=> MediaProjectionManager use
Hope it can help you !! 希望它可以帮助您!
requestcode is always -1 if it give some output you have to check resultcode and is 1.like this 如果requestcode提供了一些输出,您必须检查resultcode,则requestcode始终为-1,像这样1
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case 1:
//do your stuff
break;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.