Skip to content

Commit f781468

Browse files
JavaClassWrapper: Add example to invoke constructor (#11155)
* JavaClassWrapper: Add example to invoke constructor
1 parent 5a99b22 commit f781468

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,23 @@ Java inner classes can be accessed using the ``$`` sign:
113113
# Do something specific on android 11 devices.
114114
else:
115115
# All other devices
116+
117+
Example: Calling a constructor
118+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119+
120+
A constructor is invoked by calling a method with the same name as the class.
121+
122+
This example creates an intent to send a text:
123+
124+
.. code-block:: gdscript
125+
126+
# Retrieve the AndroidRuntime singleton.
127+
var android_runtime = Engine.get_singleton("AndroidRuntime")
128+
if android_runtime:
129+
var Intent = JavaClassWrapper.wrap("android.content.Intent")
130+
var activity = android_runtime.getActivity()
131+
var intent = Intent.Intent() # Call the constructor.
132+
intent.setAction(Intent.ACTION_SEND)
133+
intent.putExtra(Intent.EXTRA_TEXT, "This is a test message.")
134+
intent.setType("text/plain")
135+
activity.startActivity(intent)

0 commit comments

Comments
 (0)