How to take screenshot in qgroundcontrol for Android?

QT 5.15.2
Android arm64-v8a
API 24: Android 7.0
QGroundControl Stable_V4.2

Hi all,
Does anybody has experience with implementing the feature of taking screenshots in QGC, in Android?
I made it work for Windows, but when I build and ruin it on Android, it is creating an empty .png with 0 bytes, it is crashing at this line:
QPixmap screenshot = screen->grabWindow(0);

void VideoManager::takeScreenshot() {
    if (QMessageBox::question(nullptr, "Take Screenshot", "Do you want to take a screenshot?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {

        QScreen *screen = QGuiApplication::primaryScreen();
        QPixmap screenshot = screen->grabWindow(0);

        QString fileName = "screenshot_" + QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss") + ".png";

        if (screenshot.save(fileName, "PNG")) {
            qDebug() << "Screenshot saved to:" << fileName;
        } else {
            qWarning() << "Failed to save screenshot!";
        }
    }
}

I also tryed this example, but still not working:
https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/desktop/screenshot?h=6.6
and it gave me “The immage could not be saved” error

And also I’ve tryed to implement the logic in the QML file, using "Window.contentItem.grabToImage(function(result)) "
but I had the same issue

Just a guess: permission issue?

Hi Julian,

I think I have all the required permissions for that:


    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" />