JavaClassWrapper.xml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. var datetime = LocalDateTime.now()
  13. var formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss")
  14. print(datetime.format(formatter))
  15. [/codeblock]
  16. [b]Warning:[/b] When calling Java methods, be sure to check [method JavaClassWrapper.get_exception] to check if the method threw an exception.
  17. </description>
  18. <tutorials>
  19. </tutorials>
  20. <methods>
  21. <method name="get_exception">
  22. <return type="JavaObject" />
  23. <description>
  24. Returns the Java exception from the last call into a Java class. If there was no exception, it will return [code]null[/code].
  25. [b]Note:[/b] This method only works on Android. On every other platform, this method will always return [code]null[/code].
  26. </description>
  27. </method>
  28. <method name="wrap">
  29. <return type="JavaClass" />
  30. <param index="0" name="name" type="String" />
  31. <description>
  32. Wraps a class defined in Java, and returns it as a [JavaClass] [Object] type that Godot can interact with.
  33. 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.
  34. [b]Note:[/b] This method only works on Android. On every other platform, this method does nothing and returns an empty [JavaClass].
  35. </description>
  36. </method>
  37. </methods>
  38. </class>