3

我正在尝试处理新的 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

知道出了什么问题吗?

4

1 回答 1

0

你有没有试过这样:查看完整示例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();
    }
}

希望它会帮助你。

于 2017-03-01T05:10:16.157 回答