#include <sstream>
#include <assert.h>
// include in android platform-9 or newer
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
...
JNIEXPORT void JNICALL Java_com_yourpackage_yourfunctionname(JNIEnv *env, jclass clazz, jobject assetManager)
{
// get assetmanager native
AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
assert(mgr != NULL);
// load file inside assets, "assets/a/b.txt"
AAsset* asset = AAssetManager_open(mgr, "a/b.txt", AASSET_MODE_UNKNOWN);
assert(asset != NULL);
// get buffer of file
char* buff = (char*) AAsset_getBuffer(asset);
assert(buff != NULL);
// print out buffer per line
const int MAX_BUF = 512;
char strbuf [MAX_BUF];
std::istringstream iss(buff);
while ( iss.getline(strbuf, MAX_BUF) )
LOGE("%s", strbuf);
AAsset_close(asset);
}
Tuesday, September 20, 2011
Using AssetManager on native language JNI, C++
Subscribe to:
Post Comments (Atom)
[ROM] Samsung S7 Stock Firmware BRI (Taiwan台灣)
Latest ROM: G930FXXU1DQEU Download: https://kfhost.net/tpl/firmwares.php?record=B7E6DE774E3811E7963AFA163EE8F90B Reference: http://...
-
In Android 4.1 (API 16) and above, MediaCodec is introduced by Android. By using MediaCodec, we can easily decode video without using Androi...
-
#include <sstream> #include <assert.h> // include in android platform-9 or newer #include <android/asset_manager.h> #inclu...
-
Latest ROM: G930FXXU1DQEU Download: https://kfhost.net/tpl/firmwares.php?record=B7E6DE774E3811E7963AFA163EE8F90B Reference: http://...
Any code or reference documentation showing how to call this function? It's mostly unhelpful to me as-is...
ReplyDeleteconsider the class:
Deleteyourpackage
public class yourpackage : extends... bla bla bla
private static native void yourfunctionname(AssetManager mgr);
yourfunctionname(mgr);