diff options
Diffstat (limited to 'platform/android/src/attach_env.cpp')
-rw-r--r-- | platform/android/src/attach_env.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/platform/android/src/attach_env.cpp b/platform/android/src/attach_env.cpp new file mode 100644 index 0000000000..6da075ee3e --- /dev/null +++ b/platform/android/src/attach_env.cpp @@ -0,0 +1,22 @@ +#include "attach_env.hpp" +#include "jni.hpp" + +namespace mbgl { +namespace android { + +UniqueEnv AttachEnv() { + JNIEnv* env = nullptr; + jint err = theJVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6); + + switch (err) { + case JNI_OK: + return UniqueEnv(env, JNIEnvDeleter(*theJVM, false)); + case JNI_EDETACHED: + return UniqueEnv(jni::AttachCurrentThread(*theJVM).release(), JNIEnvDeleter(*theJVM, true)); + default: + throw std::system_error(err, jni::ErrorCategory()); + } +} + +} +} |