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. How to get screenshot in Java code on Android?
Forum Update on Monday, May 27th 2025

How to get screenshot in Java code on Android?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 363 Views
  • 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.
  • M Offline
    M Offline
    mikhail_kr
    wrote on last edited by mikhail_kr
    #1

    I need to make a screenshot in native Java code executed from QAndroidJniObject calls. The screenshot is to be stored inside android.graphics.Bitmap instance.

    To accomplish this I get the android.R.id.content view by this code

        ```
    

    QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
    "activity", "()Landroid/app/Activity;");
    QAndroidJniObject frameLayout = activity.callObjectMethod("findViewById","(I)Landroid/view/View;",
    0x01020002); // Hard coded value of android.R.id.content

    Then pass the "frameLayout" value to this Java method:
    
        public static Bitmap loadBitmapFromView(View view) {
            View screenView = view.getRootView();
            screenView.setDrawingCacheEnabled(true);
            Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
            screenView.setDrawingCacheEnabled(false);
            return bitmap;
        }
    
    But this does not work. I get only a big transparent rectangle on the Bitmap.
    
    What is the right way of taking screenshots from the Java code on Qt applications (QWidget without Qml)
    (It is quite important to not use QPixmap/QByteArray etc. and generate screenshot inside Java code)
    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