MCPcopy Create free account
hub / github.com/SatDump/SatDump / getAppFilesDir

Function getAppFilesDir

android/main.cpp:198–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198std::string getAppFilesDir(struct android_app *app)
199{
200 JavaVM *java_vm = app->activity->vm;
201 JNIEnv *java_env = NULL;
202
203 jint jni_return = java_vm->GetEnv((void **)&java_env, JNI_VERSION_1_6);
204 if (jni_return == JNI_ERR)
205 throw std::runtime_error("Could not get JNI environement");
206
207 jni_return = java_vm->AttachCurrentThread(&java_env, NULL);
208 if (jni_return != JNI_OK)
209 throw std::runtime_error("Could not attach to thread");
210
211 jclass native_activity_clazz = java_env->GetObjectClass(app->activity->clazz);
212 if (native_activity_clazz == NULL)
213 throw std::runtime_error("Could not get MainActivity class");
214
215 jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "getAppDir", "()Ljava/lang/String;");
216 if (method_id == NULL)
217 throw std::runtime_error("Could not get methode ID");
218
219 jstring jstr = (jstring)java_env->CallObjectMethod(app->activity->clazz, method_id);
220
221 const char *_str = java_env->GetStringUTFChars(jstr, NULL);
222 std::string str(_str);
223 java_env->ReleaseStringUTFChars(jstr, _str);
224
225 jni_return = java_vm->DetachCurrentThread();
226 if (jni_return != JNI_OK)
227 throw std::runtime_error("Could not detach from thread");
228
229 return str;
230}
231
232std::string getPluginsDir(struct android_app *app)
233{

Callers 1

android_mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected