處理錯誤

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())

如要進一步瞭解錯誤狀態,請參閱「使用媒體工作階段:狀態和錯誤」。