Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[ Native ]: Using Java functions & 3rd-party libraries in Qt for Android [closed]

Tags:

android

qt

mosync

Recently I use qt to write a android app.
But I have a big question, can I use/call some native android APIS, such as call special activity?

e.g, In Android SDK I call contacts in java:
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI); startActivityForResult(intent, PICK_CONTACT);

Is there a some c++ wrapper libraries for java android sdk APIs?

Or if I need a some special component (that has written with java), can I have it in my qt android program?
Or make a program with mixed pages/activities of "pure qt" and "standard java" or "C++ android NDK" ?

(I ask this question because I have a experience with MOSYNC framework, that was a good one but you have been limited to its own libraries, you couldn't use any external libraries or android standard APIs, ...)

Thanks in advance.

EDIT: according to improvements in JNI ( http://qt-project.org/doc/qt-5/qtandroidextras-index.html), I have a question: can I use 'any' android Java third-party libraries in my qt project? As I use those libraries in Java SDK projects?

like image 595
hich9n Avatar asked Aug 05 '13 07:08

hich9n


People also ask

What is native modifier in Java?

The native modifier indicates that a method is implemented in platform-dependent code, often seen in C language. Native modifier indicates that a method is implemented in platform-dependent code, often in C.

What is the difference between the Java method and native method?

A Java method is generically a code block with a name that you can write using plain java. A native method is a method that is linked to a native library.


2 Answers

In order to do what you want, you need to call Java code from your C++ code, through JNI. I don't know any C++ wrapper libraries for this. You will need to get the Java VM from JNI_OnLoad, and when you want to call a Java method you will need to attach the VM to your thread, with gives you a JNIEnv, which you can use to find the class you want and call methods on it. This link should help with the details.

As to whether it is worth it to use QT to develop Android applications, yes, if you need cross-platform support and want to deploy the same application to Android, Linux, Windows, etc. If you are only developing Android apps, then in my experience it is easier and faster to use Android directly.

like image 124
Logan Pickup Avatar answered Nov 16 '22 02:11

Logan Pickup


I am not sure how you are proceeding with "Qt for Android". But at this point of time, this idea is officially supported by the KDE team (K Desktop Environment). They call it KDE Necessitas project. And they have released the first beta of this project on October 2012.

So basically when you install the Necessitas SDK, you probably get these things installed.

  1. Qt Creator - The Qt IDE customized for Android.
  2. Android NDK - For building the shared object out of the Qt code.
  3. Android SDK - Customized with Qt support.

Using the customized Qt Creator, you can

  1. Create an Android UI project.
  2. Design the UI in integrated Qt Designer.
  3. Compile the C++ code to build the .so file and wrap it with the Java code.
  4. Create the APK and deploy.
  5. Debug the APK.

One major concern I have with Qt for Android is regarding the UI. The UI have the native look and feel of KDE 4.x (The same which runs on desktops). The android UI themes (Holo etc.) are not fully available yet.

And since this project is still beta, I am not sure about the availability of wrapper classes/functions for the Android native features. Please go through the official documentation for more details.

Hope this helps.

like image 40
gnuanu Avatar answered Nov 16 '22 02:11

gnuanu