Flutter : PlatformException(no_available_camera, 没有可用于拍照的相机。, null, null)
Posted
技术标签:
【中文标题】Flutter : PlatformException(no_available_camera, 没有可用于拍照的相机。, null, null)【英文标题】:Flutter : PlatformException(no_available_camera, No cameras available for taking pictures., null, null) 【发布时间】:2021-01-05 06:02:39 【问题描述】:伙计们!我正面临这个相机版本。它发生在我合并我的项目之后。它说没有可用的相机,但当时它运行良好。请看一看!
E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(no_available_camera, No cameras available for taking pictures., null, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
<asynchronous suspension>
#2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
#3 MethodChannelImagePicker.pickImagePath (package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart:62:21)
#4 MethodChannelImagePicker.pickImage (package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart:30:25)
#5 ImagePicker.getImage (package:image_picker/image_picker.dart:101:21)
#6 _ImageEvaluationState.getImage (package:PhotoEarn/screens/camera/image_evaluation.dart:201:38)
#7 _ImageEvaluationState.build.<anonymous closure> (package:PhotoEarn/screens/camera/image_evaluation.dart:1099:33)
#8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
#9 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
#10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
#11 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
#12 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5)
#13 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:259:7)
#14 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:157:27)
#15 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:362:20)
#16 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:338:22)
#17 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:267:11)
#18 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:295:7)
#19 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:240:7)
#20 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:213:7)
#21 _rootRunUnary (dart:async/zone.dart:1206:13)
#22 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#23 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
#24 _invoke1 (dart:ui/hooks.dart:265:10)
#25 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
请查看此错误消息并在此提供帮助。我期待收到大家的来信。提前谢谢你。
【问题讨论】:
我猜这个问题在flutter的master分支中已经修复了,尝试切换到master再试一次 【参考方案1】:如果您的 compileSdkVersion
和 targetSdkVersion
为 30(或更高),则将查询信息添加到您的 android 清单文件中,直接在清单标记下:
<manifest package="your.app.package.name">
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
</manifest>
这应该可以解决您的问题。
【讨论】:
在哪个文件夹?? manifest 通常位于 android/app/src/main 中。 对于那些不熟悉手动编辑清单的人来说,仅供参考,我不确定添加QUERY_ALL_PACKAGES
是否是正确的解决方案,因为目标是仅访问相机。如果targetSdkVersion=30
(或更高版本),将<queries>
添加到您的AndroidManifest.xml
看起来是一个更好的解决方案 - https://***.com/a/63246789/268156
<manifest package="com.example">
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
...
</manifest>
【讨论】:
这是迄今为止最好和最安全的解决方案。它完美地工作。我不知道为什么它没有被接受,但它确实比 QUERY_ALL_PACKAGES 好得多,谷歌也可以禁止【参考方案3】:我面临同样的问题。对于android,您需要在AndroidManifest.xml 文件中添加Camera 权限和Query all packages 权限,如下所示:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
【讨论】:
【参考方案4】:如果你的目标是android 11/android sdk 30或以上,你需要在android manifest xml文件中添加以下权限。
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
它可能会引发另一个警告,但您可以暂时忽略它。问候。
【讨论】:
【参考方案5】:我在Emulator
上进行测试,当我切换到Real device
时,一切正常。
【讨论】:
以上是关于Flutter : PlatformException(no_available_camera, 没有可用于拍照的相机。, null, null)的主要内容,如果未能解决你的问题,请参考以下文章
[Flutter] flutter项目一直卡在 Running Gradle task 'assembleDebug'...
flutter 日志输出,Flutter打印日志,flutter log,flutter 真机日志
Flutter开发 Flutter 包和插件 ( Flutter 包和插件简介 | 创建 Flutter 插件 | 创建 Dart 包 )
如何解决flutter gradle build error?C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991