Android alert display functionality using JNI
This commit is contained in:
parent
1227f1e7f4
commit
5056563f5d
5 changed files with 64 additions and 3 deletions
|
|
@ -11,6 +11,7 @@
|
|||
#if defined(__ANDROID__)
|
||||
#include <android/log.h>
|
||||
#include <dlfcn.h>
|
||||
#include <android/native_window_jni.h>
|
||||
|
||||
android_app* androidApp;
|
||||
|
||||
|
|
@ -292,6 +293,23 @@ namespace vks
|
|||
vks::android::screenDensity = AConfiguration_getDensity(config);
|
||||
AConfiguration_delete(config);
|
||||
}
|
||||
|
||||
// Displays a native alert dialog using JNI
|
||||
void showAlert(const char* message) {
|
||||
JNIEnv* jni;
|
||||
androidApp->activity->vm->AttachCurrentThread(&jni, NULL);
|
||||
|
||||
jstring jmessage = jni->NewStringUTF(message);
|
||||
|
||||
jclass clazz = jni->GetObjectClass(androidApp->activity->clazz);
|
||||
// Signature has to match java implementation (arguments)
|
||||
jmethodID methodID = jni->GetMethodID(clazz, "showAlert", "(Ljava/lang/String;)V");
|
||||
jni->CallVoidMethod(androidApp->activity->clazz, methodID, jmessage);
|
||||
jni->DeleteLocalRef(jmessage);
|
||||
|
||||
androidApp->activity->vm->DetachCurrentThread();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue