我正在尝试处理新的Android Lollipop MediaProjection API。
我发现(至少在我的股票三星Galaxy S4 jfltexx上)当我开始打算获得捕获屏幕的权限(ProjectionManager.createScreenCaptureIntent()
)时,除非我在之前的尝试中选中了"不要再问",否则我不会在onActivityResult
中得到结果。。。
private static final int ALLOW_SCREENSHOT_REQ = 102;
{
...
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
System.out.println("request permission");
startActivityForResult(mProjectionManager.createScreenCaptureIntent(), ALLOW_SCREENSHOT_REQ);
}
...
}
以及结果处理:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
System.out.println("RebootActivity.onActivityResult(" + requestCode + "," + resultCode + ", data)");
}
权限对话框显示得很好,但我的活动被隐藏了,它从未进入onActivityResult
。
知道出了什么问题吗?
你这样尝试过吗:参见完整示例android ScreenCapture
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_MEDIA_PROJECTION) {
if (resultCode != Activity.RESULT_OK) {
Log.i(TAG, "User cancelled");
Toast.makeText(getActivity(), R.string.user_cancelled, Toast.LENGTH_SHORT).show();
return;
}
Activity activity = getActivity();
if (activity == null) {
return;
}
Log.i(TAG, "Starting screen capture");
mResultCode = resultCode;
mResultData = data;
setUpMediaProjection();
setUpVirtualDisplay();
}
}
希望它能帮助你。