modified for Android JNI