Tuesday, August 3, 2010

Getting Internal Storage Directory in Android NDK

The function name should be changed to your package name and activity class name.

Writtin in C++.


JNIEXPORT void JNICALL Java_com_jongwook_test_TestActivity_test(JNIEnv * env, jobject obj)
{
jclass cls = env->GetObjectClass(obj);
jmethodID getFilesDir = env->GetMethodID(cls, "getFilesDir", "()Ljava/io/File;");
jobject dirobj = env->CallObjectMethod(obj,getFilesDir);
jclass dir = env->GetObjectClass(dirobj);
jmethodID getStoragePath =
env->GetMethodID(dir, "getAbsolutePath", "()Ljava/lang/String;");
jstring path=(jstring)env->CallObjectMethod(dirobj, getStoragePath);
const char *pathstr=env->GetStringUTFChars(path, 0);
chdir(pathstr);
env->ReleaseStringUTFChars(path, pathstr);
}

No comments:

Post a Comment