You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter升级Target SDK 30后相机异常,如何配置Android清单替代全包查询权限?

Fixing Camera Availability Issue After Target SDK 30 Upgrade (Android 11 Package Visibility)

Hey there! I’ve dealt with this exact problem when updating Flutter apps to target SDK 30, so I know how frustrating that PlatformException(no_available_camera) error can be. The good news is you don’t need the overly permissive QUERY_ALL_PACKAGES permission—here’s the proper, privacy-compliant fix:

Why This Happens

Android 11 introduced package visibility restrictions, which means your app can no longer automatically see all other apps installed on the device. Since your Flutter camera functionality relies on launching system camera apps (or third-party camera apps), your app needs explicit permission to "see" those camera apps now.

The Correct Android Manifest Configuration

Add a <queries> block inside your AndroidManifest.xml (under the root <manifest> tag) to declare exactly which camera-related apps/intents your app needs access to. This tells Android to grant visibility only to the apps relevant to your camera feature, not every app on the device.

Here’s the code to add:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.your.app.package">

    <!-- Keep your existing camera permission -->
    <uses-permission android:name="android.permission.CAMERA" />

    <!-- Android 11+ Package Visibility for Camera -->
    <queries>
        <!-- Allow your app to find apps that respond to the camera capture intent -->
        <intent>
            <action android:name="android.media.action.IMAGE_CAPTURE" />
        </intent>

        <!-- Optional: Add specific system camera packages for broader compatibility (varies by manufacturer) -->
        <package android:name="com.google.android.GoogleCamera" />
        <package android:name="com.android.camera2" />
    </queries>

    <application ...>
        <!-- Your app components go here -->
    </application>
</manifest>

Breakdown of the Configuration

  • The <intent> block targets apps that handle the android.media.action.IMAGE_CAPTURE intent—this is the standard intent used by Flutter camera plugins (like image_picker) to launch a camera app. This ensures your app can discover all camera apps that support taking photos.
  • The optional <package> entries are for common system camera apps (Google Camera and stock Android Camera2). Adding these can help with compatibility across different device manufacturers, but the <intent> block alone should work for most cases.

Verify the Fix

After adding this configuration, rebuild your Flutter app. The no_available_camera error should disappear, and your camera functionality will work as expected—all while staying compliant with Android’s privacy guidelines.

内容的提问来源于stack exchange,提问作者Md Golam Rahman Tushar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 17:22:47