You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Update the documentation for JavaClassWrapper and AndroidRuntimePlugin
Follow-up to https://github.com/godotengine/godot-docs/pull/10979
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
[b]Warning:[/b] When calling Java methods, be sure to check [method JavaClassWrapper.get_exception] to check if the method threw an exception.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Integrating with Android APIs">$DOCS_URL/tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.html</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_exception">
|
||||
|
||||
@@ -34,51 +34,21 @@ import org.godotengine.godot.Godot
|
||||
import org.godotengine.godot.variant.Callable
|
||||
|
||||
/**
|
||||
* Provides access to the Android runtime capabilities.
|
||||
* Built-in Godot Android plugin used to provide access to the Android runtime capabilities.
|
||||
*
|
||||
* For example, from gdscript, developers can use [getApplicationContext] to access system services
|
||||
* and check if the device supports vibration.
|
||||
*
|
||||
* var android_runtime = Engine.get_singleton("AndroidRuntime")
|
||||
* if android_runtime:
|
||||
* print("Checking if the device supports vibration")
|
||||
* var vibrator_service = android_runtime.getApplicationContext().getSystemService("vibrator")
|
||||
* if vibrator_service:
|
||||
* if vibrator_service.hasVibrator():
|
||||
* print("Vibration is supported on device!")
|
||||
* else:
|
||||
* printerr("Vibration is not supported on device")
|
||||
* else:
|
||||
* printerr("Unable to retrieve the vibrator service")
|
||||
* else:
|
||||
* printerr("Couldn't find AndroidRuntime singleton")
|
||||
*
|
||||
*
|
||||
* Or it can be used to display an Android native toast from gdscript
|
||||
*
|
||||
* var android_runtime = Engine.get_singleton("AndroidRuntime")
|
||||
* if android_runtime:
|
||||
* var activity = android_runtime.getActivity()
|
||||
*
|
||||
* var toastCallable = func ():
|
||||
* var ToastClass = JavaClassWrapper.wrap("android.widget.Toast")
|
||||
* ToastClass.makeText(activity, "This is a test", ToastClass.LENGTH_LONG).show()
|
||||
*
|
||||
* activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(toastCallable))
|
||||
* else:
|
||||
* printerr("Unable to access android runtime")
|
||||
* @see <a href="https://docs.godotengine.org/en/latest/tutorials/platform/android/javaclasswrapper_and_androidruntimeplugin.html">Integrating with Android APIs</a>
|
||||
*/
|
||||
class AndroidRuntimePlugin(godot: Godot) : GodotPlugin(godot) {
|
||||
override fun getPluginName() = "AndroidRuntime"
|
||||
|
||||
/**
|
||||
* Provides access to the application context to GDScript
|
||||
* Provides access to the application [android.content.Context] to GDScript
|
||||
*/
|
||||
@UsedByGodot
|
||||
fun getApplicationContext() = activity?.applicationContext
|
||||
|
||||
/**
|
||||
* Provides access to the host activity to GDScript
|
||||
* Provides access to the host [android.app.Activity] to GDScript
|
||||
*/
|
||||
@UsedByGodot
|
||||
override fun getActivity() = super.getActivity()
|
||||
|
||||
Reference in New Issue
Block a user