From 5ed267887646ce6491a87c1f2467f1d3778e0acd Mon Sep 17 00:00:00 2001 From: Noah Lessard Date: Mon, 20 Oct 2025 23:48:11 -0500 Subject: [PATCH] Add Android Gallery Example to JavaClassWrapper Squashed version of commits made in #11393 --- ...aclasswrapper_and_androidruntimeplugin.rst | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.rst b/tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.rst index 7346761a00e..3e7f1f4b368 100644 --- a/tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.rst +++ b/tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.rst @@ -133,3 +133,28 @@ This example creates an intent to send a text: intent.putExtra(Intent.EXTRA_TEXT, "This is a test message.") intent.setType("text/plain") activity.startActivity(intent) + +Example: Saving an image to the Android gallery +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: gdscript + + # Retrieve the AndroidRuntime singleton. + var android_runtime = Engine.get_singleton("AndroidRuntime") + if android_runtime: + var Intent = JavaClassWrapper.wrap("android.content.Intent") + var activity = android_runtime.getActivity() + var intent = Intent.Intent() + + # Create the File and Uri. + var Uri = JavaClassWrapper.wrap("android.net.Uri") + var File = JavaClassWrapper.wrap("java.io.File") + var file = File.File(file_path_to_image_here) + var uri = Uri.fromFile(file) + + # Set Action and Data of Intent. + intent.setAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE) + intent.setData(uri) + + # Broadcast it. + activity.sendBroadcast(intent)