NDK JNI - How call java function which returning array?

2,457 views
Skip to first unread message

Aristarh Smertin

unread,
Feb 16, 2012, 8:32:37 AM2/16/12
to android-ndk
My goal was to read just a text file under assets folder. But because
assets folder can be reached from c++ code only like a part of ZIP, i
use libzip to get file and then read it with zip_fread function. Well
it's works fine.

But i think what it can be easy done with JNI call to java to like

static byte[] getFileContents(String fileName){
assetInfo = assetsManager.openFD(%file_name%);
InputStream input = assetInfo.createInputStream();
byte[] buffer = new byte[assetInfo.getLenght()];
input.read(buffer, 0, assetInfo.getLenght());
return buffer;
}

But how to call this from C++ with JNI?

There is no (*env)->CallStaticArrayMethod() exists.

P.S. maybe there is some other ways to get file contents in assets
folder with NDK?


Mārtiņš Možeiko

unread,
Feb 16, 2012, 1:39:07 PM2/16/12
to andro...@googlegroups.com
Because all arrays are objects, you should use
CallStaticObjectMethod() and cast return type to jbyteArray.

--
Mārtiņš Možeiko

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>

Reply all
Reply to author
Forward
0 new messages