diff android/dw.cpp @ 2486:cec43818bd3e

Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 27 Apr 2021 00:16:56 +0000
parents cb5b67154399
children 83f8f4f58a98
line wrap: on
line diff
--- a/android/dw.cpp	Mon Apr 26 21:56:37 2021 +0000
+++ b/android/dw.cpp	Tue Apr 27 00:16:56 2021 +0000
@@ -592,6 +592,27 @@
  */
 int API dw_messagebox(const char *title, int flags, const char *format, ...)
 {
+    va_list args;
+    char outbuf[1025] = {0};
+    JNIEnv *env;
+
+    va_start(args, format);
+    vsnprintf(outbuf, 1024, format, args);
+    va_end(args);
+
+    if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
+    {
+        // Construct a String
+        jstring jstr = env->NewStringUTF(outbuf);
+        jstring jstrtitle = env->NewStringUTF(title);
+        // First get the class that contains the method you need to call
+        jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
+        // Get the method that you want to call
+        jmethodID messageBox = env->GetMethodID(clazz, "messageBox",
+                                                  "(Ljava/lang/String;Ljava/lang/String;I)I");
+        // Call the method on the object
+        return env->CallIntMethod(_dw_obj, messageBox, jstrtitle, jstr, flags);
+    }
     return 0;
 }