Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Android + Qt 5.2 beta ] Unable to call Android Java class from c++



  • I'm enable to call android java class from c++,
    I tried to follow the below link, but it didn't work

    http://doc-snapshot.qt-project.org/qt5-stable/qtandroidextras-notification-example.html

    main.cpp
    @#include <QtGui/QGuiApplication>
    #include "qtquick2applicationviewer.h"
    #include"notificationclient.h"
    #include <QtDebug>
    #include <QQmlContext>
    #include<QQmlEngine>
    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;
    NotificationClient *notificationClient = new NotificationClient(&viewer);
    viewer.rootContext()->setContextProperty("notificationClient", notificationClient);
    viewer.setMainQmlFile&#40;QStringLiteral("qml/qttest/main.qml"&#41;);
    viewer.showExpanded();
    
    return app.exec();
    

    }
    @

    my java code is :

    @package org.qtproject.example.notification;

    import android.os.Bundle;
    import android.app.Activity;
    import android.util.Log;
    import android.view.Menu;

    public class NotificationClient extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.ff);
    }

    public static void notify(String s){
    Log.d("notify", "0000000000000");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.notification_client, menu);
    return true;
    }

    }
    @



  • Instead of calling it from c++, I changed the generated Java code it and it worked as charm ;)


Log in to reply