2020-01-19 23:19:21 +01:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-07-06 10:08:05 +02:00
<class name= "JavaClassWrapper" inherits= "Object" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2020-01-19 23:19:21 +01:00
<brief_description >
2024-01-05 11:38:27 +01:00
Provides access to the Java Native Interface.
2020-01-19 23:19:21 +01:00
</brief_description>
<description >
2024-01-05 11:38:27 +01:00
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).
[b]Note:[/b] This singleton is only available in Android builds.
2024-08-20 16:53:57 -05:00
[codeblock]
var LocalDateTime = JavaClassWrapper.wrap("java.time.LocalDateTime")
var DateTimeFormatter = JavaClassWrapper.wrap("java.time.format.DateTimeFormatter")
var datetime = LocalDateTime.now()
var formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss")
print(datetime.format(formatter))
[/codeblock]
2025-02-14 09:27:40 -06:00
[b]Warning:[/b] When calling Java methods, be sure to check [method JavaClassWrapper.get_exception] to check if the method threw an exception.
2020-01-19 23:19:21 +01:00
</description>
<tutorials >
2025-05-30 09:39:53 -07:00
<link title= "Integrating with Android APIs" > $DOCS_URL/tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.html</link>
2020-01-19 23:19:21 +01:00
</tutorials>
<methods >
2025-02-14 09:27:40 -06:00
<method name= "get_exception" >
<return type= "JavaObject" />
<description >
Returns the Java exception from the last call into a Java class. If there was no exception, it will return [code]null[/code].
[b]Note:[/b] This method only works on Android. On every other platform, this method will always return [code]null[/code].
</description>
</method>
2020-01-19 23:19:21 +01:00
<method name= "wrap" >
2021-07-30 15:28:05 +02:00
<return type= "JavaClass" />
2022-08-06 21:11:48 +03:00
<param index= "0" name= "name" type= "String" />
2020-01-19 23:19:21 +01:00
<description >
2024-01-05 11:38:27 +01:00
Wraps a class defined in Java, and returns it as a [JavaClass] [Object] type that Godot can interact with.
2025-03-19 19:12:43 +05:30
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.
2024-01-05 11:38:27 +01:00
[b]Note:[/b] This method only works on Android. On every other platform, this method does nothing and returns an empty [JavaClass].
2020-01-19 23:19:21 +01:00
</description>
</method>
</methods>
</class>