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. Communication between C++ and Java without using JNI
Forum Updated to NodeBB v4.3 + New Features

Communication between C++ and Java without using JNI

Scheduled Pinned Locked Moved Mobile and Embedded
1 Posts 1 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.
  • B Offline
    B Offline
    benlau
    Qt Champions 2016
    wrote on 20 Jul 2015, 04:34 last edited by benlau
    #1

    Hi,

    QuickAndroid project has released a new version with a feature for communication between C++ and Java without using JNI.

    It provides a component called System Dispatcher for message delivery. The design is quite similar to the AppDispatcher from QuickFlux project. But the delivered message can be passed from C++ to Java and vice versa. Data type conversion is handled automatically.

    C++

    QASystemDispatcher::dispatch(QString name, QVariantMap message);
    

    quickandroid/qasystemdispatcher.h at 4339203dbb87eed0fda611151481216db004385a · benlau/quickandroid

    Java

    class SystemDispatcher {
    public static void dispatch ( String name , Map message ) { ... }
    }
    

    quickandroid/SystemDispatcher.java at 4339203dbb87eed0fda611151481216db004385a · benlau/quickandroid

    The supported data types:

    int <-> Integer
    bool <-> Boolean
    QString <-> java.lang.String
    QVariantMap <-> java.util.Map (Non-nested)

    Example code:
    quickandroid/examples/quickandroidexample at master · benlau/quickandroid

    Deliver message from QML

    SystemDispatcher.dispatch("Notifier.notify",{
       title: "Quick Android Example",
       message: "Hello!"
    });
    

    quickandroid/NotificationDemo.qml at d76397a9c21732439fa9dffeff9bc6246e67e2bc · benlau/quickandroid

    Handle the message from Java

    public void onDispatched(String name , Map message) {
       if (name.equals("Notifier.notify")) {
          notificationManagerNotify(data);
       }
        return;
    }
    

    quickandroid/ExampleActivity.java at d76397a9c21732439fa9dffeff9bc6246e67e2bc · benlau/quickandroid

    1 Reply Last reply
    1

    1/1

    20 Jul 2015, 04:34

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved