摘要:Android fopen usage
reference http://skwtchen.blogspot.tw/2011/01/ndkassets.html
there are 2 ways to use fopen
1st
將asset或res中檔案的附檔名存成.mp3或.png之類,來避免打包成APK時檔案被壓縮。取得file descriptor, offset, 及length並透過JNI傳遞到C code。從Java File Descriptor object中取得OS file descriptor,並使用fdopen及fseek取得所要的檔案。
the files u want to use fopen u have to ensure the files's extension must be .mp3 or .png or it will be compressed by zip
then fetch file descriptor in jave code
2nd
首先在java code中要先取得APK檔的所在路徑,並將之透過JNI傳給C code,接下來就可以透過libzip所提供的function,像是zip_open, zip_fopen, zip_fread等來讀取所需要的檔案啦!! 下面的範例是把APK檔中所有檔案print出來。
get apk file full path by jin ,and use libzup to get ur things
=============================================================
if u are using nativeActive u could do as below
c++ call java by jni
it will be like this
jni call c++
it will be like this
below is how to get apkpath
ApplicationInfo appInfo = null; PackageManager packMgmr = this.getPackageManager(); try { appInfo = packMgmr.getApplicationInfo("com.skwt.gl2jni", 0); } catch (NameNotFoundException e) { e.printStackTrace(); throw new RuntimeException("Unable to locate assets, aborting..."); } String apkFilePath = appInfo.sourceDir; GL2JNILib.initAPK(apkFilePath);
or jusr simplify to do this in ur cpp