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!
Answer
questions
xzaleksey
Thanks!
We will look into it as idea is good. If you wish you can even create a pull request for this issue.
Related questions
No questions were found.