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

相关内容

热门资讯

玩家必备科技!四川游戏家园通用... 玩家必备科技!四川游戏家园通用辅助(辅助挂)aa poker透视软件(原来是真的有挂);是一款可以让...
发现一款!同乡游辅助软件(辅助... 发现一款!同乡游辅助软件(辅助挂)aapoker免费透视脚本(果然是有挂);1、让任何用户在无需AI...
我来教教大家!科乐填大坑破解版... 我来教教大家!科乐填大坑破解版安卓(辅助挂)wepoker黑侠辅助器(确实有挂),科乐填大坑破解版安...
科普!途游辅助软件网站(辅助挂... 科普!途游辅助软件网站(辅助挂)aa poker透视软件(往昔存在有挂);途游辅助软件网站中的10万...
科技分享!玫瑰大厅辅助(辅助挂... 科技分享!玫瑰大厅辅助(辅助挂)hhpoker辅助器视频(固有真的是有挂);玫瑰大厅辅助最新版本免费...
玩家攻略!大众互娱辅助器(辅助... 《玩家攻略!大众互娱辅助器(辅助挂)红龙poker有辅助吗(往昔是真的有挂)》 大众互娱辅助器软件透...
推荐十款!打哈儿辅助软件(辅助... 推荐十款!打哈儿辅助软件(辅助挂)wepoker透视脚本网页(好像是有挂);小薇(透视辅助)致您一封...
终于清楚!广东雀神祈福真的有用... 终于清楚!广东雀神祈福真的有用吗(辅助挂)wepoker好友助力码(好像真的有挂);一、广东雀神祈福...
带你了解!卡五星辅助器(辅助挂... 带你了解!卡五星辅助器(辅助挂)wepoker辅助透视软件(起初真的是有挂);卡五星辅助器辅助器中分...
让我来分享经验!微乐家乡破解版... 让我来分享经验!微乐家乡破解版(辅助挂)佛手在线大菠萝辅助(原生有挂);佛手在线大菠萝辅助是一种具有...