static void SystemActivityNotifications_notify(jint type) { jobject delegate = SystemActivityNotifications_delegate; if (delegate) { JavaVM *vm = SystemActivityNotifications_vm; if (vm) { JNIEnv *env; if (0 == vm->AttachCurrentThreadAsDaemon((void **) &env, NULL)) { jclass clazz = env->GetObjectClass(delegate); if (clazz) { jmethodID methodID = env->GetMethodID(clazz,"notify", "(I)V"); if (methodID) env->CallVoidMethod(delegate, methodID, type); } env->ExceptionClear(); } } } }
Jvm::Env::Env(bool daemon) : env(NULL), detach(false) { JavaVM* jvm = Jvm::get()->jvm; // First check if we are already attached. int result = jvm->GetEnv(JNIENV_CAST(&env), Jvm::get()->version); // If we're not attached, attach now. if (result == JNI_EDETACHED) { if (daemon) { jvm->AttachCurrentThreadAsDaemon(JNIENV_CAST(&env), NULL); } else { jvm->AttachCurrentThread(JNIENV_CAST(&env), NULL); } detach = true; } }