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, //

相关内容

热门资讯

透视挂!wpk透视辅助靠谱吗,... 透视挂!wpk透视辅助靠谱吗,wepoker数据分析(详细辅助德州论坛);1、wpk透视辅助靠谱吗透...
wepoke黑科技!poker... wepoke黑科技!poker辅助工具(透视)先前存在有挂(详细辅助新2025版),您好,wepok...
透视挂透视!德普之星辅助器ap... 透视挂透视!德普之星辅助器app,fishpoker透视底牌(详细辅助实用技巧);1、构建自己的德普...
wepoke ai辅助!微扑克... wepoke ai辅助!微扑克真的有挂存在吗(透视)总是真的有挂(详细辅助教你攻略)是一款可以让一直...
微扑克ai辅助工具!智星德州菠... 微扑克ai辅助工具!智星德州菠萝app下载(透视)原本真的有挂(详细辅助wpk教程)1、金币登录送、...
透视中牌率!hhpoker透视... 透视中牌率!hhpoker透视功能如何下载,拱趴大菠萝挂(详细辅助可靠教程)亲,关键说明,hhpok...
微扑克辅助软件!德扑之星怎么让... 微扑克辅助软件!德扑之星怎么让系统给好牌(透视)其实是有挂(详细辅助详细教程)1)微扑克辅助软件辅助...
透视黑科技!hhpoker辅助... 透视黑科技!hhpoker辅助软件,wepoker透视脚本免费(详细辅助安装教程);1、全新机制【w...
aapoker俱乐部!云扑克德... 您好,aapoker俱乐部这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩...
透视科技!智星德州菠萝插件官网... 透视科技!智星德州菠萝插件官网,wepoker脚本下载(详细辅助详细教程)1)智星德州菠萝插件官网辅...