summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRodrigo Escar <[email protected]>2022-03-18 07:41:41 -0300
committerGitHub <[email protected]>2022-03-18 11:41:41 +0100
commit9723489cccabb84c53b2d9823e9b56c3ae6cd282 (patch)
tree34e5cd7302cdc7fd8fa5b2be69b6ebcb94cd41e8 /src
parent3d812f8d0c0f3a854311f73957740c7aa846c5a4 (diff)
downloadraylib-9723489cccabb84c53b2d9823e9b56c3ae6cd282.tar.gz
raylib-9723489cccabb84c53b2d9823e9b56c3ae6cd282.zip
Implements OpenURL() for Android Platform (#2396)
Diffstat (limited to 'src')
-rw-r--r--src/rcore.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/rcore.c b/src/rcore.c
index 127c8a1e..7614d3f9 100644
--- a/src/rcore.c
+++ b/src/rcore.c
@@ -242,6 +242,7 @@
//#include <android/sensor.h> // Required for: Android sensors functions (accelerometer, gyroscope, light...)
#include <android/window.h> // Required for: AWINDOW_FLAG_FULLSCREEN definition and others
#include <android_native_app_glue.h> // Required for: android_app struct and activity management
+ #include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL()]
#include <EGL/egl.h> // Native platform windowing system interface
//#include <GLES2/gl2.h> // OpenGL ES 2.0 library (not required in this module, only in rlgl)
@@ -3458,6 +3459,29 @@ void OpenURL(const char *url)
#if defined(PLATFORM_WEB)
emscripten_run_script(TextFormat("window.open('%s', '_blank')", url));
#endif
+#if defined(PLATFORM_ANDROID)
+ JNIEnv *env = NULL;
+ JavaVM *vm = CORE.Android.app->activity->vm;
+ (*vm)->AttachCurrentThread(vm, &env, NULL);
+
+ jstring urlString = (*env)->NewStringUTF(env, url);
+ jclass uriClass = (*env)->FindClass(env, "android/net/Uri");
+ jmethodID uriParse = (*env)->GetStaticMethodID(env, uriClass, "parse", "(Ljava/lang/String;)Landroid/net/Uri;");
+ jobject uri = (*env)->CallStaticObjectMethod(env, uriClass, uriParse, urlString);
+
+ jclass intentClass = (*env)->FindClass(env, "android/content/Intent");
+ jfieldID actionViewId = (*env)->GetStaticFieldID(env, intentClass, "ACTION_VIEW", "Ljava/lang/String;");
+ jobject actionView = (*env)->GetStaticObjectField(env, intentClass, actionViewId);
+ jmethodID newIntent = (*env)->GetMethodID(env, intentClass, "<init>", "(Ljava/lang/String;Landroid/net/Uri;)V");
+ jobject intent = (*env)->AllocObject(env, intentClass);
+
+ (*env)->CallVoidMethod(env, intent, newIntent, actionView, uri);
+ jclass activityClass = (*env)->FindClass(env, "android/app/Activity");
+ jmethodID startActivity = (*env)->GetMethodID(env, activityClass, "startActivity", "(Landroid/content/Intent;)V");
+ (*env)->CallVoidMethod(env, CORE.Android.app->activity->clazz, startActivity, intent);
+
+ (*vm)->DetachCurrentThread(vm);
+#endif
}
}