Skip to content

Commit c393e8a

Browse files
committed
add android gallery example to javaclasswrapper doc
1 parent c362d2e commit c393e8a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,27 @@ This example creates an intent to send a text:
133133
intent.putExtra(Intent.EXTRA_TEXT, "This is a test message.")
134134
intent.setType("text/plain")
135135
activity.startActivity(intent)
136+
137+
Example: Using an Intent to Save an Image to an Android Gallery
138+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
139+
140+
.. code-block:: gdscript
141+
# Retrieve the AndroidRuntime singleton.
142+
var android_runtime = Engine.get_singleton("AndroidRuntime")
143+
if android_runtime:
144+
var Intent = JavaClassWrapper.wrap("android.content.Intent")
145+
var Uri = JavaClassWrapper.wrap("android.net.Uri")
146+
var File = JavaClassWrapper.wrap("java.io.File")
147+
148+
# Create the File and Uri
149+
var file = File.File(file_path_to_image_here)
150+
var uri = Uri.fromFile(file)
151+
152+
# Build the Intent
153+
var intent = Intent.Intent()
154+
intent.setAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)
155+
intent.setData(uri)
156+
157+
# Broadcast it
158+
var activity = android_runtime.getActivity()
159+
activity.sendBroadcast(intent)

0 commit comments

Comments
 (0)