我尝试了以下两种方法但失败了:
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
QPlatformNativeInterface *interface = QApplication::platformNativeInterface();
jobject activity = (jobject)interface->nativeResourceForIntegration("QtActivity");
答案 0 :(得分:0)
好的,我参加了QT 5.2,这对我有用:
第一
你的.pro:中的
QT += gui-private
现在在你的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;