相機預覽和媒體投影
透過集合功能整理內容
你可以依據偏好儲存及分類內容。

等級 3 - 可供大螢幕使用
相機預覽
相機是最重要的 Android 應用程式之一。相機觀景窗是應用程式的視窗,用於算繪相機感應器輸出內容 (相機預覽畫面)。
相機感應器具有固定位置和固定顯示比例,通常會以橫向方向輸出圖片資料。不過,取景器必須符合裝置的直向和橫向螢幕方向、折疊式裝置的折疊和展開狀態,以及多視窗模式中的不同視窗大小。
在多視窗模式和摺疊式裝置上,取景器可在橫向裝置上顯示直向畫面,或在直向裝置上顯示橫向畫面。相機應用程式通常必須旋轉圖片預覽畫面,以符合取景器的方向。即使取景器和相機感應器的方向相同,兩者的顯示比例仍可能不同。
您的應用程式會在 UI 變更方向和大小時,調整相機感應器圖片的方向和顯示比例,以便與應用程式 UI 的方向和顯示比例相符。
如要瞭解如何管理相機預覽畫面,請參閱下列開發人員指南:
媒體投影功能會擷取裝置螢幕或應用程式視窗的內容,並在電視等其他裝置上顯示擷取的內容。
媒體投影應用程式必須註冊服務權限、管理使用者同意聲明、將擷取的內容調整為符合目標裝置的方向和顯示比例,並啟用投影功能的客製化設定。
如要進一步瞭解實作方式,請參閱「媒體投放」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Camera preview and media projection\n\nTIER 3 --- Large screen ready\n| **Objective:** Make your app [large screen ready](/docs/quality-guidelines/large-screen-app-quality#large_screen_ready) by meeting the [LS-CM1](/docs/quality-guidelines/large-screen-app-quality#LS-CM1) camera preview and [LS-CM2](/docs/quality-guidelines/large-screen-app-quality#LS-CM2) media projection requirements of the [Large screen app quality](/docs/quality-guidelines/large-screen-app-quality) guidelines.\n\nCamera preview\n--------------\n\nCamera is one of the most important Android apps. The camera viewfinder is a window into the app, a rendering of the camera sensor output (the camera preview).\n\nCamera sensors have a fixed position and fixed aspect ratio and typically output their image data in landscape orientation. The viewfinder, however, must conform to portrait and landscape device orientations, folded and unfolded states of foldable devices, and different window sizes in multi‑window mode.\n\nIn multi‑window mode and on foldables, the viewfinder can be portrait on landscape devices or landscape on portrait devices. Camera apps often must rotate the image preview to match the orientation of the viewfinder. And even when the viewfinder and camera sensor are in the same orientation, their aspect ratios can differ.\n\nYour app has the challenge of orienting and scaling the camera sensor image to match the orientation and aspect ratio of the app's UI as the UI changes orientation and size.\n\nTo learn how to manage camera preview, see the following developer guides:\n\n- [Camera preview](/training/camera2/camera-preview)\n- [CameraX overview](/training/camerax)\n\nMedia projection\n----------------\n\nMedia projection captures the contents of a device screen or app window and displays the captured content on another device, such as a TV.\n\nMedia projection apps must register a service permission, manage user consent, orient and scale the captured content to match the orientation and aspect ratio of the target device, and enable customization of the projection.\n\nFor implementation details, see [Media projection](/media/grow/media-projection)."]]