0

I am completely lost on this. Hopefully someone can point me in the right direction.

I am using: https://code.google.com/archive/p/android-serialport-api/

I have included the pre-built libserial_port.so in my project, along with SerialPort.h and SerialPort.c. Compiles with no warnings or errors.

How do I now open the serial port? The .c/.h files provide two C functions, but to call them requires a JNIEnv * which I don't have in my C++ project.

I can see that JNIEnv is a struct that is a table of function pointers.

I am using Visual Studio 2017 with the Android extension, and I have created a NativeActivity project.

Thanks!

Andy
  • 938
  • 1
  • 10
  • 21
  • 1
    Try: https://stackoverflow.com/questions/12900695/how-to-obtain-jni-interface-pointer-jnienv-for-asynchronous-calls Remember that the NativeActivity still has a Java owner. This is the Java side: https://developer.android.com/reference/android/app/NativeActivity – Richard Critten Aug 14 '18 at 15:46
  • Any particular reason you want to use C? This can be done directly in Java, as in this app: https://play.google.com/store/apps/details?id=com.silicau.pro8051programmer – Susmit Agrawal Aug 14 '18 at 15:48
  • @susmit-agrawal I am porting an existing C library to Android. – Andy Aug 14 '18 at 15:57

1 Answers1

0

I solved this with:

state->activity->env

which gives me access to the current JNIEnv *. However there is so little information on Android development problems that relate to Visual Studio that I think I will switch to Android Studio and stop swimming against the current.

Andy
  • 938
  • 1
  • 10
  • 21