[android] Use jni.hpp in http_request_android.cpp

This commit is contained in:
John Firebaugh
2016-02-28 20:30:58 -08:00
parent 9e0be736fc
commit 235f4ee6f6
8 changed files with 224 additions and 402 deletions

View File

@@ -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());
}
}
}
}