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德州局透视(辅助挂)详细开挂辅助挂;无需打开直接搜索打开薇:1...
玩家必看科普!中至余干六副里,... 边锋老友填大坑辅助是一款可以让一直输的玩家,快速成为一个“必胜”的ai辅助神器,有需要的用户可以加我...
辅助透视!微信老友广东辅助,h... 辅助透视!微信老友广东辅助,hhpoker辅助靠谱吗(辅助挂)详细开挂辅助平台您好:微信老友广东辅助...
科普分享!途游手游辅助脚本平台... 【亲,途游手游辅助脚本平台 这款游戏可以开挂的,确实是有挂的,很多玩家在这款途游手游辅助脚本平台中打...
透视了解!蘑菇云辅助脚本,we... 透视了解!蘑菇云辅助脚本,werplan外卦神器(辅助挂)详细开挂辅助神器;无需打开直接搜索打开薇:...
一分钟快速了解!湖南赣湘互娱辅... 一分钟快速了解!湖南赣湘互娱辅助,福建兄弟13水破解器(存在有挂辅助平台)这是一款可以让一直输的玩家...
透明私人局!pokemmo脚本... 透明私人局!pokemmo脚本辅助,hhpoker有透视功能吗(辅助挂)详细开挂辅助软件;无需打开直...
分享实测!兴动互娱游戏辅助怎么... 分享实测!兴动互娱游戏辅助怎么用,光明大厅微信链接辅助试用(确实有挂辅助开挂平台) 了解更多开挂安装...
透视玄学!德州局透视脚本免费版... 透视玄学!德州局透视脚本免费版下载手机版,哈糖大菠萝挂(辅助挂)详细开挂辅助下载;无需打开直接搜索薇...
今日公布!榆林打锅子辅助器,微... 今日公布!榆林打锅子辅助器,微信微乐辅助器免费安装(有挂秘籍辅助平台)这是一款可以让一直输的玩家,快...