首页 > 解决方案 > Qt调用具有多个参数的java方法

问题描述

我检查了 android 的 Qt Notifier 示例:https ://doc.qt.io/qt-5/qtandroidextras-notification-example.html 在此示例中,使用 2 个参数调用 Java 方法,如下所示:

void NotificationClient::updateAndroidNotification()
{
    QAndroidJniObject javaNotification = QAndroidJniObject::fromString(m_notification);
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/notification/NotificationClient",
                                       "notify",
                                       "(Ljava/lang/String;)V",
                                       javaNotification.object<jstring>());
}

我很难理解我应该在这里传递哪些参数来调用带有 2 个参数的函数,而不是一个。例如,该函数当前采用 1 个参数:

public static void notify(String s)
{
    if (m_notificationManager == null) {
        m_notificationManager = 

(NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
            m_builder = new Notification.Builder(m_instance);
            m_builder.setSmallIcon(R.drawable.icon);
            m_builder.setContentTitle("A message from Qt!");
        }

        m_builder.setContentText(s);
        m_notificationManager.notify(1, m_builder.build());
    }

我可以在方法本身()中添加另一个public static void notify(String s, String x),但是如何处理 cpp 部分?

标签: javaandroidc++qt

解决方案


它应该是

QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/notification/NotificationClient",
                                   "notify",
                                   "(Ljava/lang/String;Ljava/lang/String;)V",
                                   javaNotification.object<jstring>(), 
                                   somethingelse.object<jstring>());

如此所述。


推荐阅读