You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

小米MI8基于Android Camera 2 API实现默认相机同款镜头切换问询

Mi 8 Lens Switching: Workarounds for Hidden Physical Camera IDs

Hey there, let's tackle this lens switching problem you're having with the Xiaomi Mi 8 (API 29). First off, I feel your frustration—MIUI has a history of restricting Camera2 API access to hide physical camera details from third-party apps, which is exactly what's happening here with your empty physicalCameraIds list.

Why You're Seeing an Empty physicalCameraIds List

Xiaomi wraps multiple physical cameras (wide and telephoto on the Mi 8) into a single logical camera device, but intentionally hides the physical IDs from public Camera2 API calls. This is a common practice among Chinese OEMs to push their first-party camera apps and limit third-party access to hardware features.

Possible Workarounds to Try

1. Enumerate All Camera Devices

Don't just stick to the primary rear logical camera. Try iterating through all camera IDs returned by CameraManager.getCameraIdList(), then query each device's characteristics to see if any correspond to the telephoto lens. Look for:

  • A different LENS_INFO_AVAILABLE_FOCAL_LENGTHS value (your current list only shows 4.216mm, which is the wide lens; telephoto should be around 8.4mm for 2x optical zoom)
  • Separate lens-specific parameters that don't match your current rear camera characteristics

It's a long shot, but some OEMs leave hidden camera entries accessible even if they're not linked to the main logical camera.

2. Trigger Lens Switch via Optical Zoom

The Mi 8 has a 2x optical telephoto lens. Instead of trying to directly select a physical camera, try setting the zoom ratio to 2.0 using CaptureRequest.CONTROL_ZOOM_RATIO. Many devices automatically switch to the telephoto lens when hitting the optical zoom threshold, even if physical IDs are hidden.

Test this by:

  1. Setting up your capture session with the logical camera
  2. Creating a CaptureRequest and setting CONTROL_ZOOM_RATIO to 2.0
  3. Checking if the focal length in the camera characteristics updates (you might need to re-query characteristics after setting the zoom)

3. (Not Recommended) Use MIUI Private APIs

Some developers have had limited success using reflection to access MIUI's private camera services, which might expose physical camera controls. However:

  • There's no official documentation for these APIs
  • They're likely to break with MIUI updates
  • Your app may get rejected from app stores for using non-public APIs

Only go this route if the above methods fail and you're building a non-distributed app.

Physical Camera IDs on Other Devices

For devices that follow Android's official Camera2 spec (like Google Pixel, Samsung Galaxy flagships with stock Android), physicalCameraIds will correctly list all physical cameras linked to a logical camera. For example, the Pixel 3's rear logical camera has two physical IDs, one for wide and one for telephoto. The issue you're facing is almost entirely OEM-specific to Xiaomi's MIUI customization.


内容的提问来源于stack exchange,提问作者koflox

火山引擎 最新活动