我正在检查Android的Qt通告程序示例: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个)来调用函数。例如,该函数当前带有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部分?
答案 0 :(得分:1)
应该是
QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/notification/NotificationClient",
"notify",
"(Ljava/lang/String;Ljava/lang/String;)V",
javaNotification.object<jstring>(),
somethingelse.object<jstring>());
如here所述。