Som e utilidades de dispositivo
A fachada Device reúne recursos pequenos e portáveis. Tudo estático.
Feedback e sistema
Device.beep(); // bip do sistema
Device.vibrate(200); // vibra 200 ms
Device.sleep(500); // pausa a thread atual 500 ms
int livre = Device.getFreeMemory();
Device.show("https://exemplo.com"); // abre URL/recurso no app externo do SO
Área de transferência
Device.clipboardCopy("texto");
String colado = Device.clipboardPaste();
Identidade e plataforma
if (Device.platform.isMobile()) { ... } // ANDROID/IPHONE/IPAD
if (Device.platform.isDesktop()) { ... } // WINDOWS/LINUX/MACOS
if (Device.platform.isIOS()) { ... } // IPHONE/IPAD
String base = Device.homeFolder; // diretório base da app
Platform: JAVA · WINDOWS · LINUX · IPHONE · ANDROID · IPAD · MACOS.
Rádios sem fio
WirelessState wifi = Device.getWirelessState(WirelessType.WIFI); // UNSUPPORTED/DISABLED/ENABLED
Device.enableWireless(WirelessType.BLUETOOTH, true);
WirelessType: WIFI · PHONE · BLUETOOTH.
Voz — TTS e STT
Device.textToVoice("Olá, mundo"); // fala o texto (TTS)
Device.voiceToText(new Device.VoiceToTextListener() { // reconhecimento de fala (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)); }
});
Os callbacks de STT chegam fora da paint thread → volte com
Component.onUI(...).
⚠️ Notas de migração
Sound.*eRadioStateforam absorvidos porDevice—Sound.tone/playnão existem mais.- No Web/TeaVM, boa parte disto é stub (vibração, rádios, voz) — trate o alvo Web.
Boas práticas
- Callbacks de voz/rádio voltam à UI com
onUI(...). - Cheque
WirelessState.UNSUPPORTEDantes de assumir que um rádio existe.
Erros comuns
- Chamar
Sound.play(...)/RadioState(removidos) — useDevice. - Tocar a UI direto no
onResultdo STT semonUI.
Veja também
Esta página foi útil?Obrigado pelo feedback!