Issue
I have compiled a C++ shared library using ndk and loaded it successfully from Android Studio but now I have a problem that the interface of my library takes a string as a path to some file as a parameter but I don't know how I should pass this path to my library and where should I put the file on my phone?
Here is how my interface looks like:
public final static native fun(String path);
Solution
Here you go, just make sure you release it when you're done.
JNIEXPORT void JNICALL Java_classes_classes_fun
(JNIEnv *env, jobject thiz, jstring path){
const char *nativePath = (*env)->GetStringUTFChars(env, path, 0);
// use your string as usual
(*env)->ReleaseStringUTFChars(env, path, nativePath);
}
Also mentioned here: How to get sent string from java code to native C in Android
As for the file handling, you can use the C++ STL libraries.
https://developer.android.com/training/data-storage/files
Describes where you can store files better than I can here.
Answered By - WLGfx
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.