相机预览和媒体投屏
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。

第 3 层级 - 支持大屏设备
相机预览
相机是最重要的 Android 应用之一。相机取景器是进入应用的窗口,是相机传感器输出(相机预览)的渲染。
相机传感器具有固定的位置和固定的宽高比,通常以横向模式输出图像数据。不过,取景器必须适应设备的纵向和横向模式、可折叠设备的折叠和展开状态,以及多窗口模式下的不同窗口大小。
在多窗口模式下和可折叠设备上,取景器可以在横屏设备上纵向显示,也可以在竖屏设备上横向显示。相机应用通常必须旋转图片预览,以匹配取景器的方向。即使取景器和摄像头传感器的方向相同,它们的宽高比也可能不同。
随着界面的屏幕方向和大小发生变化,您的应用需要调整摄像头传感器图像的方向和缩放比例,使其与应用界面的屏幕方向和宽高比保持一致。
如需了解如何管理相机预览,请参阅以下开发者指南:
媒体投影会截取设备屏幕或应用窗口中的内容,并在其他设备(例如电视)上显示所截取的内容。
媒体投影应用必须注册服务权限、管理用户同意情况、调整所捕获内容的方向和缩放比例以匹配目标设备的方向和宽高比,并启用投影自定义。
如需了解实现详情,请参阅媒体投影。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):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)."]]