Skip to content
CrossFly is 100% open sourceFollow us on GitHub
CrossFlyCrossFly
Get started

This page was machine-translated from Portuguese and may contain errors. The Portuguese version is canonical.

Device sound and utilities

The Device facade gathers small, portable features. Everything static.

Feedback and system

Device.beep();              // system beep
Device.vibrate(200);        // vibrates 200 ms
Device.sleep(500);          // pauses the current thread 500 ms
int livre = Device.getFreeMemory();
Device.show("https://exemplo.com");   // opens a URL/resource in the OS's external app

Clipboard

Device.clipboardCopy("texto");
String colado = Device.clipboardPaste();

Identity and platform

if (Device.platform.isMobile()) { ... }     // ANDROID/IPHONE/IPAD
if (Device.platform.isDesktop()) { ... }    // WINDOWS/LINUX/MACOS
if (Device.platform.isIOS()) { ... }        // IPHONE/IPAD
String base = Device.homeFolder;            // app base directory

Platform: JAVA · WINDOWS · LINUX · IPHONE · ANDROID · IPAD · MACOS.

Wireless radios

WirelessState wifi = Device.getWirelessState(WirelessType.WIFI);   // UNSUPPORTED/DISABLED/ENABLED
Device.enableWireless(WirelessType.BLUETOOTH, true);

WirelessType: WIFI · PHONE · BLUETOOTH.

Voice — TTS and STT

Device.textToVoice("Olá, mundo");   // speaks the text (TTS)

Device.voiceToText(new Device.VoiceToTextListener() {   // speech recognition (STT)
   public void onStart() {}
   public void onFinish() {}
   public void onResult(String texto) { Component.onUI(() -> campo.text(texto)); }
   public void onError(int code, String msg) { Component.onUI(() -> Hint.show(msg, 2000)); }
});

STT callbacks arrive off the paint thread → come back with Component.onUI(...).

⚠️ Migration notes

  • Sound.* and RadioState were absorbed into Device — Sound.tone/play no longer exist.
  • On Web/TeaVM, much of this is a stub (vibration, radios, voice) — handle the Web target.

Best practices

  • Voice/radio callbacks come back to the UI with onUI(...).
  • Check WirelessState.UNSUPPORTED before assuming a radio exists.

Common mistakes

  • Calling Sound.play(...)/RadioState (removed) — use Device.
  • Touching the UI directly in the STT onResult without onUI.

See also

Was this page helpful?