Friendiqa/source-android/androidnative.pri
2017-11-24 22:12:03 +01:00
..
ci v0.1 2017-11-08 21:15:07 +01:00
cpp/AndroidNative v0.1 2017-11-08 21:15:07 +01:00
docs v0.1 2017-11-08 21:15:07 +01:00
examples/androidnativeexample v0.1 2017-11-08 21:15:07 +01:00
java/src/androidnative v0.1 2017-11-08 21:15:07 +01:00
qml v0.1 2017-11-08 21:15:07 +01:00
tests/instrument v0.1 2017-11-08 21:15:07 +01:00
.gitignore v0.1.1 2017-11-24 22:12:03 +01:00
.gitmodules v0.1.1 2017-11-24 22:12:03 +01:00
.travis.yml v0.1.1 2017-11-24 22:12:03 +01:00
androidnative.pri v0.1 2017-11-08 21:15:07 +01:00
LICENSE v0.1 2017-11-08 21:15:07 +01:00
qpm.json v0.1 2017-11-08 21:15:07 +01:00
README.md v0.1 2017-11-08 21:15:07 +01:00

Calling Android functions from Qt without using JNI

It is a fork of the Quick Android project that aims to provide a library to access Android functions from Qt/QML without using JNI.

Remarks: This project only support gradle build system.

Features

  1. SystemDispatcher - A message queue for C++/Qt and Java/Android
  2. Send message in C++, receive in Java and vice versa.
  3. Data type will be converted automatically (e.g QMap <-> java.util.Map). No need to write in JNI.
  4. It could be used to write your own Java code
  5. Bundled Components
  6. Image Picker
  7. Toast
  8. Wrapper of android.os.Environment / android.os.Debug / MediaScannerConnection

C++ API

  1. Environment::getExternalStoragePublicDirectory()
  2. MediaScannerConnection::scanFile()
  3. Debug::getNativeHeapSize()
  4. Debug::getNativeHeapAllocatedSize()

The functions above do not require to config gradle before using.

QML Components

    import AndroidNative 1.0
  1. ImagePicker
  2. Toast

SystemDispatcher

SystemDispatcher is a message queue component for delivering action message between C++/QML and Java. Data type in message is converted to the target platform automatically (e.g QMap <-> java.util.Map) . So that user doesn't need to write JNI to access their Java functions.

Moreover, SystemDispatcher is compilable on a non-Android platform. It doesn't cause any trouble to run on your development host.

// C++ Example

#include <AndroidNative>

// Load a Java class. It will trigger the code within `static` block
SystemDispatcher::instance()->loadClass("androidnative.example.ExampleService");

QVariantMap message;
message["value1"] = 1;
message["value2"] = 2.0;
message["value3"] = "3";

// Dispatch a message
SystemDispatcher::instance()->dispatch("androidnative.example.dummyAction", message);

// QML Example

import AndroidNative 1.0

Item {

  Component.onCompleted: {
    var message = {
      value1: 1,
      value2: 2.0,
      value3: "3"
    }
    SystemDispatcher.dispatch("androidnative.example.dummyAction", message);
  }
}
// Java Receiver

public class ExampleService {

    static {

        SystemDispatcher.addListener(new SystemDispatcher.Listener() {

            public void onDispatched(String type , Map message) {

                if (type.equals("androidnative.example.dummyAction")) {
                    // Process then dispatch a response back to C++/QML                    
                    SystemDispatcher.dispatch(("androidnative.example.response");
                
                    return;
                }
                return;
            }        
        });        
     }
}

// Listen from QML

Connections {
  target: SystemDispatcher
  onDispatched: {
    // process the message
  }
}

Supported data type:

Qt Java
int int
bool boolean
QString String
QVariantList List
QVariantMap Map

Installation Instruction

androidnative.pri/installation.md at master · benlau/androidnative.pri

Example

An example program is available at: androidnative.pri/examples/androidnativeexample at master · benlau/androidnative.pri

example1.png (533×472)