How I can call java method(non-static) from native(C++) code? I saw some examples on Internet ut don't understood exactly(it' dont works for me).
I trying something like this code:
java code:
public void displayInterstitial() {
if(adView!=null)
{
if (adView.getVisibility() == AdView.VISIBLE) {
adView.post(new Runnable() {
public void run() {
adView.setVisibility(AdView.INVISIBLE);
}
});
}
}
}
C++ code:
// JNI OnLoad
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
{
g_JavaVM = vm;
return JNI_VERSION_1_6;
}
JNIEnv* MenuState::getJniEnv() {
JavaVMAttachArgs attachArgs;
attachArgs.version = JNI_VERSION_1_6;
//attachArgs.name = ">>>NativeThread__Any";
// attachArgs.group = NULL;
JNIEnv* env;
if (g_JavaVM->AttachCurrentThread(&env, &attachArgs) != JNI_OK) {
env = NULL;
}
return env;
}
void MenuState::displayInterstitial()
{
JNIEnv *env = getJniEnv();
jclass cls = env->FindClass("org/libsdl/app/SDLActivity");
jmethodID dispin = env->GetMethodID(cls, "displayInterstitial", "()V");
env->CallVoidMethod(obj, dispin);
}
Sorry for maybe duplicate question. How i can get jobject(obj) for this line env->CallVoidMethod(obj, dispin); ?