טיפול בשגיאות
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
Android Auto ו-Android Automotive (AAOS) מגדירים את מצב ההפעלה ל-STATE_ERROR
ומציגים למשתמש הודעת שגיאה מותאמת לשפה שלו. לאחר מכן, האפליקציות יכולות להציג את ההודעה למשתמש.
כדי לטפל בשגיאה, צריך לספק הודעת שגיאה עם setErrorMessage
.
במאמר בנושא PlaybackStateCompat
מפורטת רשימה של קודי שגיאה שאפשר להשתמש בהם כשמעצבים את הודעת השגיאה, כדי לציין את מהות השגיאה. אם משתמש צריך לבצע פעולה בטלפון כדי לפתור בעיה, צריך לכלול את ההוראה הזו בהודעת השגיאה.
הודעות השגיאה צריכות להיות מוצגות למשתמשים, וצריכות להיות מותאמות ללוקאל של המשתמש. לדוגמה, אם התוכן לא זמין באזור של המשתמש, צריך להשתמש ב-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())
במאמר שימוש בסשן מדיה: מצבים ושגיאות תוכלו לקרוא מידע נוסף על מצבי שגיאה.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-22 (שעון UTC).
[null,null,["עדכון אחרון: 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)."]]