13

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?

Alaa Salah
  • 1,047
  • 3
  • 12
  • 28
hich9n
  • 1,578
  • 2
  • 15
  • 32
  • 2
    QT uses the android NDK, which should have a wrapper function, doesn't it? – Sebastian Lange Aug 05 '13 at 08:08
  • 1
    Yes sebastian, NDK does, but this does not mean that QT also has a wrapper to use android sdk/ndk. – hich9n Aug 06 '13 at 10:49
  • I don't think there are any special wrappers for android-related functions. This would still be required to be implemented with NDK-calls. QT will have the standard "QT" functions working for UI and basic io operations, managing objects etc. But accessing special android features will still be left out i think. – Sebastian Lange Aug 06 '13 at 10:58
  • Android development is best with eclipse. – Niko Aug 13 '13 at 17:02
  • 2
    The Eclipse comment seems pretty subjective. Why is Android development best in Eclipse in relation to the question that was asked? And how would using Eclipse make the question that was asked easier to solve than using any other IDE? – Jerry Jeremiah Aug 20 '13 at 00:41
  • 1
    I have just found this example of calling Java code from an Android application: http://qt-project.org/doc/qt-5/qtandroidextras-notification-example.html – Michal Fapso May 27 '14 at 08:44
  • 1
    I think this question can be opened. @sashoalm – hich9n Nov 22 '14 at 11:40

3 Answers3

9

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.

Logan Pickup
  • 2,294
  • 2
  • 22
  • 29
3

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.

gnuanu
  • 2,252
  • 3
  • 29
  • 42
-1

You can program in C/C++ using the Android NDK. You'll have to wrap your c++ codebase in a static library and load that through a Java wrapper & JNI.

The standard NDK does not support RTTI and a lot of the functionality of standard c++ is also not available such as std::string, etc. To solve this you can recompile the NDK. Dmitry Moskalchuk supplies a modified version of the NDK that supports this at http://www.crystax.net/android/ndk-r3.php. This modified version works on all Android phones that run on an ARM processor.

Note:JNI calls can decrease your performance by a lot. Java isn't that hard tho -- if you know how to program in C/C++. The advantage of Java is that the application can run on any device running Android, where as NDK applications depend on the architecture it was compiled for.

Shiva
  • 6,677
  • 4
  • 36
  • 61
  • 2
    The NDK does support RTTI, exceptions, and STL. See: http://developer.android.com/tools/sdk/ndk/index.html – Frohnzie Aug 19 '13 at 16:25