我正在制作一个图书馆应用程序,使用谷歌破解板检测Android中的本机崩溃.每当我的主应用程序发生本机崩溃时,breakpad都会调用以下回调.从这个回调中,我需要使用JNI在java类中调用静态void方法.
bool breakpad_callback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded) {
JNIEnv* env = NULL;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
{
if(isDebug)
LOGI("Failed to get the environment");
return false;
}
if(isDebug)
LOGI("attaching thread ...");
vm->AttachCurrentThread(&env, NULL);
if(isDebug)
LOGI("handle exception");
ExceptionHandlerClass = (jclass)env->NewGlobalRef(env->FindClass("com/abc/Myclass"));
if (ExceptionHandlerClass == NULL)
LOGE("Could not find java class");
ExceptionHandlerMethod = env->GetStaticMethodID(ExceptionHandlerClass, "handleException", "()V");
if (ExceptionHandlerMethod == NULL)
LOGE("Could not bind exception handler method");
// handle exception
env->CallStaticVoidMethod(ExceptionHandlerClass, ExceptionHandlerMethod);
if(env->ExceptionCheck()) {
LOGI("got exception");
env->ExceptionDescribe();
}
if(isDebug)
LOGI("exception handled");
} …Run Code Online (Sandbox Code Playgroud)