profile
viewpoint

Ask questionsversion 1.0.3 on Android 10 using PixelCopy API fails, reverting to 1.0.0 uses MediaProjection and works

on Android 10 (Samsung A9) using the latest version with the following code you get a black screenshot:

public class ScreenshotActivity extends Activity {
    private ScreenshotManager _mgr = null;
    private ScreenshotResult _scrRes = null;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        // ----> THIS IS NEVER CALLED
        super.onActivityResult(requestCode, resultCode, data);
        _mgr.onActivityResult(requestCode, resultCode, data);
        finishActivity(requestCode);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // setup screenshotty
        ScreenshotManagerBuilder bld = new ScreenshotManagerBuilder(this);
        _mgr = bld.build();
        _scrRes = _mgr.makeScreenshot();

        // observe the result
        _scrRes.observe((result) -> {
            // ----> THIS IS CALLED, BUT THE RESULTING SCREENSHOT IS ALL BLACK
            Screenshot scr = (Screenshot)result;
            saveScreenshot(scr);
            finish();
            return Unit.INSTANCE;
        }, (ex -> {
            // failure
            finish();
            return Unit.INSTANCE;
        }));
    }
}

after a few digging around, i think it's the new Pixel API which fails somehow (but still report success), and that is used as default on android 10. as you can see from the comment, the observe successful callback is called without the OnActivityResult() handler called first, thus resulting in the black screenshot.

reverting to version 1.0.0 (which uses the mediaprojection api) works correctly, btw .... still, the PixelCopy API implementation is probably flawed/wrong/not applicable. i would suggest to offer a way to select the API to use instead, without defaulting 'blindly'.... unless until you find a workaround.

cheers!

bolteu/screenshotty

Answer questions valerino

Thanks!

We will look into it as idea is good. If you wish you can even create a pull request for this issue.

Anyway, i looked a bit into it. Probably it is working as intended, coz the PixelCopy API I don't think it can be used to take screenshot of the whole device screen but only for your Activity. So it could be reasonable it returns a black screen, I was trying to capture whole screen screenshot using an invisible Activity on top. Reasonable to add the option to use whichever API one chooses, but still I think this is not a bug and the issue may be closed if you wish.....

useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List