Gestire gli errori
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Android Auto e Android Automotive (AAOS) impostano lo stato di riproduzione su
STATE_ERROR
e forniscono un messaggio di errore localizzato visibile all'utente. Le app possono
quindi mostrare il messaggio all'utente.
Per risolvere un errore, fornisci un messaggio di errore con setErrorMessage
.
Consulta la sezione PlaybackStateCompat
per un elenco dei codici di errore che puoi utilizzare quando
progetti il messaggio di errore per indicare la natura dell'errore. Se un utente
deve interagire con il proprio smartphone per risolvere un problema, includi questa istruzione
nel messaggio di errore.
I messaggi di errore devono essere rivolti all'utente e mirati alle impostazioni internazionali dell'utente. Ad esempio, se i contenuti non sono disponibili nelle impostazioni internazionali dell'utente, utilizza ERROR_CODE_NOT_AVAILABLE_IN_REGION
.
Kotlin
mediaSession.setPlaybackState(
PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_ERROR)
.setErrorMessage(PlaybackStateCompat.ERROR_CODE_NOT_AVAILABLE_IN_REGION, getString(R.string.error_unsupported_region))
// ...and any other setters.
.build())
Java
mediaSession.setPlaybackState(
new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_ERROR)
.setErrorMessage(PlaybackStateCompat.ERROR_CODE_NOT_AVAILABLE_IN_REGION, getString(R.string.error_unsupported_region))
// ...and any other setters.
.build())
Per saperne di più sugli stati di errore, consulta la sezione
Utilizzo di una sessione multimediale: stati ed errori.
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-08-22 UTC.
[null,null,["Ultimo aggiornamento 2025-08-22 UTC."],[],[],null,["# Handle errors\n\nAndroid Auto and Android Automotive (AAOS) set the playback state to\n`STATE_ERROR` and provide a user-facing, localized error message. The apps can\nthen display the message to the user.\n\nTo address an error, you provide an error message with [`setErrorMessage`](/reference/android/support/v4/media/session/PlaybackStateCompat.Builder#setErrorMessage(int,%20java.lang.CharSequence)).\n\nSee [`PlaybackStateCompat`](/reference/android/support/v4/media/session/PlaybackStateCompat) for a list of the error codes you can use when\ndesigning the error message to indicate the nature of the error. If a user\nmust interact with their phone to resolve an issue, include this instruction\nin the error message.\n\nError messages must be user-facing and targeted to the user's locale. For\nexample, if content is not available in the user's locale, use\n[`ERROR_CODE_NOT_AVAILABLE_IN_REGION`](/reference/android/support/v4/media/session/PlaybackStateCompat#ERROR_CODE_NOT_AVAILABLE_IN_REGION()). \n\n### Kotlin\n\n mediaSession.setPlaybackState(\n PlaybackStateCompat.Builder()\n .setState(PlaybackStateCompat.STATE_ERROR)\n .setErrorMessage(PlaybackStateCompat.ERROR_CODE_NOT_AVAILABLE_IN_REGION, getString(R.string.error_unsupported_region))\n // ...and any other setters.\n .build())\n\n### Java\n\n mediaSession.setPlaybackState(\n new PlaybackStateCompat.Builder()\n .setState(PlaybackStateCompat.STATE_ERROR)\n .setErrorMessage(PlaybackStateCompat.ERROR_CODE_NOT_AVAILABLE_IN_REGION, getString(R.string.error_unsupported_region))\n // ...and any other setters.\n .build())\n\nTo learn more about error states, see\n[Using a media session: States and errors](/guide/topics/media-apps/working-with-a-media-session#errors)."]]