Skip to content

Commit 5ed2678

Browse files
committed
Add Android Gallery Example to JavaClassWrapper
Squashed version of commits made in #11393
1 parent c362d2e commit 5ed2678

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,28 @@ 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: Saving an image to the Android gallery
138+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139+
140+
.. code-block:: gdscript
141+
142+
# Retrieve the AndroidRuntime singleton.
143+
var android_runtime = Engine.get_singleton("AndroidRuntime")
144+
if android_runtime:
145+
var Intent = JavaClassWrapper.wrap("android.content.Intent")
146+
var activity = android_runtime.getActivity()
147+
var intent = Intent.Intent()
148+
149+
# Create the File and Uri.
150+
var Uri = JavaClassWrapper.wrap("android.net.Uri")
151+
var File = JavaClassWrapper.wrap("java.io.File")
152+
var file = File.File(file_path_to_image_here)
153+
var uri = Uri.fromFile(file)
154+
155+
# Set Action and Data of Intent.
156+
intent.setAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)
157+
intent.setData(uri)
158+
159+
# Broadcast it.
160+
activity.sendBroadcast(intent)

0 commit comments

Comments
 (0)