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 activity object in QT5.2?
Forum Updated to NodeBB v4.3 + New Features

How to get activity object in QT5.2?

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 3 Posters 1.3k Views 1 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.
  • R Offline
    R Offline
    range007
    wrote on last edited by
    #1

    I have tried the fellowing two methods but failed:
    @QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");@

    @QPlatformNativeInterface *interface = QApplication::platformNativeInterface();
    jobject activity = (jobject)interface->nativeResourceForIntegration("QtActivity");@

    1 Reply Last reply
    0
    • GianlucaG Offline
      GianlucaG Offline
      Gianluca
      wrote on last edited by
      #2

      I used the second solution in one of my projects and works very well.

      Why it fails in your case ?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        T.Iotti
        wrote on last edited by
        #3

        Ok, I was in QT 5.2 and this worked for me:

        first:

        in your .pro:
        @QT += gui-private@

        now in your cpp:
        @

        #include <QAndroidJniObject>
        #include <qpa/qplatformnativeinterface.h>

        QAndroidJniObject getMainActivity()
        {
        QPlatformNativeInterface *interface = QApplication::platformNativeInterface();
        QAndroidJniObject activity = (jobject)interface->nativeResourceForIntegration("QtActivity");

        if(!activity.isValid())
        qDebug()<<"CLASS NOT VALID!!!!!!!!";
        else
        qDebug()<<"HORRAY!";

        return activity;
        }
        @

        I also like to thanks the MontezooM post which helped me to figure out

        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