You need to pass the private files path from Java to C, as a string.
Alternatively, you could pass the context and call getFilesDir() through JNI but
that's unnecessary overhead IMO. There may be some other solution with the new
APIs introduced with Android 2.3, but that won't work on earlier Android releases.
--
Olivier
java side:
----------------------------
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
{
...
java.io.File dataDir = getFilesDir();
Log.w(TAG, String.format("external files dir is %s", dataDir.toString()));
JNI_SetFilesPath(dataDir.toString());
...
}
public static native void JNI_SetFilesPath(String);
static {
System.loadLibrary("my_library");
}
}
----------------------------------
native side:
----------------------------------
#include "jni.h"
char g_FilesDir[MAX_PATH];
void JNICALL JNI_SetFilesPath( JNIEnv* env, jobject thiz, jstring path)
{
strncpy(g_FilesDir,env-> GetStringUTFChars(path, null),MAX_PATH);
}
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
JNIEnv* env = NULL;
vm->GetEnv((void**) &env, JNI_VERSION_1_4)
const char* activityClass = "com/example/app/MainActivity";
JNINativeMethod activityMethods[] = {
{"JNI_SetFilesPath", "(Ljava/lang/String;)V", (void*)JNI_SetFilesPath }
};
jclass clazz = env->FindClass(className);
env->RegisterNatives(clazz, activityMethods, 1) ;
return JNI_TRUE;
}
----------------------------------
HTH
> --
> 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.
>