java - File operations JNI -



java - File operations JNI -

i'm new android , jni. want access files in device. i've added permissions manifest yet doesn't work.

the java code:

public class mainactivity extends actionbaractivity { public native string setfilepath(string path); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); textview tv = new textview(this); tv.settext( "1111" ); setcontentview(tv); string path = environment.getexternalstoragedirectory().getpath()+"/xyz"; log.i("java ", path); setfilepath(path); } }

the c code:

jint java_package_mainactivity_setfilepath(jnienv* env, jobject this,jstring path){ path = (*env)->getstringutfchars( env, path , null ) ; __android_log_print(android_log_debug, "so", "fopen(%s)", path); file* file = fopen(path,"ab+"); (*env)->releasestringutfchars( env, path , path ); fputs("testing!\n", file); fclose(file); homecoming 0; }

an error comes as:

fatal signal 11 (sigsegv) @ 0x0000000c (code=1), thread 16152

// path jstring passed arg of function char *path = (*env)->getstringutfchars( env, path , null ) ; __android_log_print(android_log_debug, "so", "fopen(%s)", path); file* file = fopen(path,"ab+"); (*env)->releasestringutfchars( env, path , path ); fputs("testing!\n", file); fclose(file);

if not work, post printed logcat.

java android c android-ndk jni

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -