| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="JavaClassWrapper" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | Provides access to the Java Native Interface. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | The JavaClassWrapper singleton provides a way for the Godot application to send and receive data through the [url=https://developer.android.com/training/articles/perf-jni]Java Native Interface[/url] (JNI). |
| 8 | [b]Note:[/b] This singleton is only available in Android builds. |
| 9 | [codeblock] |
| 10 | var LocalDateTime = JavaClassWrapper.wrap("java.time.LocalDateTime") |
| 11 | var DateTimeFormatter = JavaClassWrapper.wrap("java.time.format.DateTimeFormatter") |
| 12 | |
| 13 | var datetime = LocalDateTime.now() |
| 14 | var formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss") |
| 15 | |
| 16 | print(datetime.format(formatter)) |
| 17 | [/codeblock] |
| 18 | [b]Warning:[/b] When calling Java methods, be sure to check [method JavaClassWrapper.get_exception] to check if the method threw an exception. |
| 19 | </description> |
| 20 | <tutorials> |
| 21 | <link title="Integrating with Android APIs">$DOCS_URL/tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.html</link> |
| 22 | </tutorials> |
| 23 | <methods> |
| 24 | <method name="get_exception"> |
| 25 | <return type="JavaObject" /> |
| 26 | <description> |
| 27 | Returns the Java exception from the last call into a Java class. If there was no exception, it will return [code]null[/code]. |
| 28 | [b]Note:[/b] This method only works on Android. On every other platform, this method will always return [code]null[/code]. |
| 29 | </description> |
| 30 | </method> |
| 31 | <method name="wrap"> |
| 32 | <return type="JavaClass" /> |
| 33 | <param index="0" name="name" type="String" /> |
| 34 | <description> |
| 35 | Wraps a class defined in Java, and returns it as a [JavaClass] [Object] type that Godot can interact with. |
| 36 | When wrapping inner (nested) classes, use [code]$[/code] instead of [code].[/code] to separate them. For example, [code]JavaClassWrapper.wrap("android.view.WindowManager$LayoutParams")[/code] wraps the [b]WindowManager.LayoutParams[/b] class. |
| 37 | [b]Note:[/b] To invoke a constructor, call a method with the same name as the class. For example: |
| 38 | [codeblock] |
| 39 | var Intent = JavaClassWrapper.wrap("android.content.Intent") |
| 40 | var intent = Intent.Intent() |
| 41 | [/codeblock] |
| 42 | [b]Note:[/b] This method only works on Android. On every other platform, this method does nothing and returns an empty [JavaClass]. |
| 43 | </description> |
| 44 | </method> |
| 45 | </methods> |
| 46 | </class> |