istereo2
diff src/android/amain.c @ 27:f0da8b2b61ec
removed iOS cpu restriction and bumped build number to 3
implemented android JNI calls to show/hide ads (untested)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 05 Oct 2015 17:15:02 +0300 |
parents | 9d53a4938ce8 |
children | c6c45fa9658d |
line diff
1.1 --- a/src/android/amain.c Mon Oct 05 06:11:54 2015 +0300 1.2 +++ b/src/android/amain.c Mon Oct 05 17:15:02 2015 +0300 1.3 @@ -2,6 +2,7 @@ 1.4 #include <stdlib.h> 1.5 #include <assert.h> 1.6 #include <EGL/egl.h> 1.7 +#include <jni.h> 1.8 #include "android_native_app_glue.h" 1.9 #include <android/window.h> 1.10 #include <android/sensor.h> 1.11 @@ -25,6 +26,10 @@ 1.12 static int width, height; 1.13 static int init_done; 1.14 1.15 +static JavaVM *jvm; 1.16 +static JNIEnv *jni; 1.17 +static jclass activity_class; 1.18 + 1.19 void android_main(struct android_app *app_ptr) 1.20 { 1.21 app_dummy(); 1.22 @@ -37,6 +42,13 @@ 1.23 1.24 start_logger(); 1.25 1.26 + jvm = app->activity->vm; 1.27 + if((*jvm)->AttachCurrentThread(jvm, &jni, 0) != 0) { 1.28 + fprintf(stderr, "failed to attach native thread to Java VM\n"); 1.29 + exit(1); 1.30 + } 1.31 + activity_class = (*jni)->GetObjectClass(jni, app->activity->clazz); 1.32 + 1.33 for(;;) { 1.34 int num_events; 1.35 struct android_poll_source *pollsrc; 1.36 @@ -69,10 +81,26 @@ 1.37 /* TODO */ 1.38 void ad_banner_show(void) 1.39 { 1.40 + jmethodID method; 1.41 + if(!jvm) return; 1.42 + 1.43 + if(!(method = (*jni)->GetMethodID(jni, activity_class, "show_ad", "()V"))) { 1.44 + fprintf(stderr, "failed to retrieve MainActivity.show_ad method\n"); 1.45 + return; 1.46 + } 1.47 + (*jni)->CallVoidMethod(jni, activity_class, method); 1.48 } 1.49 1.50 void ad_banner_hide(void) 1.51 { 1.52 + jmethodID method; 1.53 + if(!jvm) return; 1.54 + 1.55 + if(!(method = (*jni)->GetMethodID(jni, activity_class, "hide_ad", "()V"))) { 1.56 + fprintf(stderr, "failed to retrieve MainActivity.hide_ad method\n"); 1.57 + return; 1.58 + } 1.59 + (*jni)->CallVoidMethod(jni, activity_class, method); 1.60 } 1.61 1.62 static void handle_command(struct android_app *app, int32_t cmd)