简体   繁体   中英

NFC implementation on Android using Qt

I'm trying to read the UID from nfc card on Android using Qt. aOn one hand, After some research, I found this class in Java for the reading. On the other hand, I've read on Qt documentation how to call and static Object from Java using QAndroidJniObject::callStaticObjectMethod , but I have no idea how to create an activity using Qt's module AndroidExtras, and make it notify when a new Intent is launch.

Does anyone have some advice to get it work? Thanks in advance,

Update: Including info on the other way around

Compared to calling java from C/C++ code calling C code from java is pretty simple, the android ndk includes several useful examples the simplest being hello ndk, all can be opened in eclipse but note you need to build the jni part with ndk-build first. The key part is getting your naming right, I followed http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/ when i was starting out, Android NDK tutorial/guide for beginners. has several other start guides.

The key parts are as following

  1. create your java activity, you can inherit QtActivity as per the notification library.

  2. Load your library (Qt will probably handle this step for you) leave off the preciding lib and trailing .so so for libstuff.so do as below

     // load the library - name matches jni/Android.mk static { System.loadLibrary("stuff"); } 
  3. Declare your C function from the java (make sure the name is the same as whatever you have in your .c file do this outside any classes

     private native String myCFunction(); 
  4. Somewhere in your java code call the myCFunction();

     String something = myCFunction(); 

There is a Qt Example that does exactly this with reasonable documentation http://doc.qt.io/qt-5/qtandroidextras-notification-example.html

Rather then calling the java NFC api directly from Qt you may want to write a wrapper function in java and call that from your C++ application. You may well also find it easier to call a C++ method from java with the result especially if the NFC library doesn't return a result imediatly.

Oracle has a JNI overview and documentation on there website http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/intro.html#wp725

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM