Platform

object Platform

Contains utilities for platform-specific code. Allows to easily determine current application platform and its version. Can execute given actions only on specific platforms.

Properties

Link copied to clipboard
val currentPlatform: Application.ApplicationType

The ApplicationType reported by the current libGDX application. Throws GdxRuntimeException when unable to determine the platform.

Link copied to clipboard

True if ApplicationType.Android is the currentPlatform.

Link copied to clipboard

True if ApplicationType.Applet is the currentPlatform.

Link copied to clipboard

True if ApplicationType.Desktop with a graphical application is the currentPlatform.

Link copied to clipboard

True if ApplicationType.HeadlessDesktop without a graphical application is the currentPlatform.

Link copied to clipboard

True if ApplicationType.iOS is the currentPlatform.

Link copied to clipboard

True if ApplicationType.Android or ApplicationType.iOS are the currentPlatform.

Link copied to clipboard

True if ApplicationType.WebGL is the currentPlatform. To determine if the application is running in an Applet, use isApplet instead.

Link copied to clipboard

Android API version on Android, major OS version on iOS, 0 on most other platforms, or -1 if unable to read.

Functions

Link copied to clipboard
inline fun <T> runOnAndroid(action: () -> T?): T?

Executes action if the currentPlatform is ApplicationType.Android. Returns action result or null.

Link copied to clipboard
inline fun <T> runOnApplet(action: () -> T?): T?

Executes action if the currentPlatform is ApplicationType.Applet. Returns action result or null.

Link copied to clipboard
inline fun <T> runOnDesktop(action: () -> T?): T?

Executes action if the currentPlatform is ApplicationType.Desktop. Returns action result or null.

Link copied to clipboard
inline fun <T> runOnHeadless(action: () -> T?): T?

Executes action if the currentPlatform is ApplicationType.HeadlessDesktop. Returns action result or null.

Link copied to clipboard
inline fun <T> runOniOS(action: () -> T?): T?

Executes action if the currentPlatform is ApplicationType.iOS. Returns action result or null.

Link copied to clipboard
inline fun <T> runOnMobile(action: () -> T?): T?

Executes action if the currentPlatform is ApplicationType.Android or ApplicationType.iOS. Returns action result or null.

Link copied to clipboard
inline fun <T> runOnVersion(minVersion: Int? = null, maxVersion: Int? = null, platform: Application.ApplicationType? = null, action: () -> T?): T?

Executes action is the current platform version (such as Android API version or iOS major OS version) is equal to or higher than minVersion and equal to or lower than maxVersion. If a platform is given, the currentPlatform must also be the same in order to execute the action.

Link copied to clipboard
inline fun <T> runOnWeb(action: () -> T?): T?

Executes action if the currentPlatform is ApplicationType.WebGL. Returns action result or null. Not that the action will not be executed in an Applet - use runOnApplet instead.