Android11MIUI13中相机不工作,抛出CameraException(error,Attempttoinvokevirtualmethod'intandroid.hardware'
创始人
2024-08-20 11:00:35
0

通过在AndroidManifest.xml文件中声明CAMERA权限并重新安装应用程序来解决此问题。以下是包含CAMERA权限声明和初始化相机的示例代码:

在AndroidManifest.xml文件中添加以下权限声明:

在您的Flutter代码中,使用以下代码初始化相机:

import 'package:camera/camera.dart';

void main() async { WidgetsFlutterBinding.ensureInitialized();

final cameras = await availableCameras(); final camera = cameras.first;

runApp( MaterialApp( theme: ThemeData.dark(), home: TakePictureScreen( // Pass the appropriate camera to the TakePictureScreen widget. camera: camera, ), ), ); }

class TakePictureScreen extends StatefulWidget { final CameraDescription camera;

const TakePictureScreen({ Key key, @required this.camera, }) : super(key: key);

@override TakePictureScreenState createState() => TakePictureScreenState(); }

class TakePictureScreenState extends State { CameraController _controller; Future _initializeControllerFuture;

@override void initState() { super.initState(); // To display the current output from the Camera, // create a CameraController. _controller = CameraController( // Get a specific camera from the list of available cameras. widget.camera, // Define the resolution to use. ResolutionPreset.high, );

// Next, initialize the controller. This returns a Future.
_initializeControllerFuture = _controller.initialize();

}

@override void dispose() { // Dispose of the controller when the widget is disposed. _controller.dispose(); super.dispose(); }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Take a picture')), // Wait until the controller is initialized before displaying the // camera preview. Use a FutureBuilder to display a loading spinner // until the controller has finished initializing. body: FutureBuilder( future: _initializeControllerFuture, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.done) { // If the Future is complete, display the preview. return CameraPreview(_controller); } else { // Otherwise, display a loading indicator. return Center(child: CircularProgressIndicator()); } }, ), floatingActionButton: FloatingActionButton( child: Icon(Icons.camera_alt), // Provide an onPressed callback. onPressed: () async { // Take the Picture in a try / catch block. If anything goes wrong, //

相关内容

热门资讯

透视计算!佛手在线大菠萝技巧(... 透视计算!佛手在线大菠萝技巧(透视)确实是有挂(详细辅助AI教程)1、游戏颠覆性的策略玩法,独创攻略...
揭秘一下!wejoker开挂,... 这是一款非常优秀的竞技联盟辅助 ia辅助检测软件,能够让你了解到竞技联盟辅助中牌率当中全部隐藏参数,...
透视中牌率!wepoker有透... 透视中牌率!wepoker有透视功能吗(透视)竟然是有挂(详细辅助专业教程);1、系统规律教程、辅助...
科技通报!werplan有挂吗... 科技通报!werplan有挂吗,拱趴大菠萝开挂方法,扑克教程(有挂方法);最新版2024是一款经典耐...
透视科技!wepoker透视有... 透视科技!wepoker透视有吗(透视)切实是有挂(详细辅助解密教程)一、wepoker透视AI软件...
一分钟秒懂!wejoker免费... 一分钟秒懂!wejoker免费脚本,hhpoker有作弊的吗,2025教程(有挂软件)关于hhpok...
透视ai代打!aapoker辅... 透视ai代打!aapoker辅助怎么用(透视)一贯真的是有挂(详细辅助线上教程)1、透视辅助简单,软...
详细说明!pokemmo脚本最... 详细说明!pokemmo脚本最新版,wepoker-h5下载,曝光教程(有挂技巧);致您一封信;亲爱...
透视总结!拱趴大菠萝挂哪里(透... 透视总结!拱趴大菠萝挂哪里(透视)本来存在有挂(详细辅助总结教程)1、下载好辅助软件之后点击打开,先...
必看攻略!hhpoker辅助软... 必看攻略!hhpoker辅助软件,hhpoker透视工具,科技教程(有挂方法);原来确实真的有挂(需...