Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Screen capture for Android
Qt 6.11 is out! See what's new in the release blog

Screen capture for Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Liorm
    wrote on last edited by
    #1

    Hi everyone

    I need to screen capture on Android. I've tried grabWindow:

          QPixmap desk = g_app->screens().at(0)->grabWindow( QDesktopWidget().winId() );
          bool x = desk.save(path3.append("/screenshot.PNG"));
    

    but x returned false. i tried to see QPixmap size:

          QByteArray bytes;
          QBuffer buffer(&bytes);
          buffer.open(QIODevice::WriteOnly);
          desk.save(&buffer, "PNG");
          qDebug() << "len " << buffer.size();
    

    the output was len 0

    any ideas?

    alternatively, any Android class I can use using JNI or something similar?

    thanks SO much for any help
    Lior

    raven-worxR 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What is the exact path you used to save the file ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Liorm
        wrote on last edited by
        #3

        @Liorm said in Screen capture for Android:

        hi and thanks
        this is the path
        QString path3 = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);

        which is evaluated to '/storage/emulated/0/Download'

        but the main point is that the QPixmap is empty... buffer.size is 0

        is grabWindow known to work in Android? i see conflicting reports

        thanks!

        1 Reply Last reply
        0
        • L Liorm

          Hi everyone

          I need to screen capture on Android. I've tried grabWindow:

                QPixmap desk = g_app->screens().at(0)->grabWindow( QDesktopWidget().winId() );
                bool x = desk.save(path3.append("/screenshot.PNG"));
          

          but x returned false. i tried to see QPixmap size:

                QByteArray bytes;
                QBuffer buffer(&bytes);
                buffer.open(QIODevice::WriteOnly);
                desk.save(&buffer, "PNG");
                qDebug() << "len " << buffer.size();
          

          the output was len 0

          any ideas?

          alternatively, any Android class I can use using JNI or something similar?

          thanks SO much for any help
          Lior

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Liorm said in Screen capture for Android:

          I need to screen capture on Android. I've tried grabWindow:

          of a QWidget or QML application?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            QDesktopWidget().winId() that's wrong.

            Take a look at the QDesktopWidget documentation on how to properly get a QDesktopWidget object.

            Note that I'm not sure what the result is on Android.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved