Convert JNI types to Native types

Graeme picture Graeme · Jun 10, 2011 · Viewed 58.5k times · Source

While there is documentation regarding turning a jstring to a native string (string nativeString = env->GetStringUTFChars(jStringVariable, NULL);) I can't find an example which will convert a jboolean to a bool or a jint to an int.

Can anyone suggest how this is achieved?

Answer

Gregory Pakosz picture Gregory Pakosz · Jun 10, 2011

You just need to cast jintto int using C style casts. Same for jboolean to bool (if you're using C99 bool type) or to uint8_t (if you're using std int types) or to unsigned char.

Open $NDK_ROOT/platforms/android-8/arch-arm/usr/include/jni.h and you'll see jint, jboolean etc are just typedefs.