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

相关内容

热门资讯

来一盘!闲来辅助平台,wepo... 来一盘!闲来辅助平台,wepoker透视挂底牌,存在挂教程(有挂教程);闲来辅助平台软件透明挂更新新...
今日头条!山西扣点工具,微信小... 今日头条!山西扣点工具,微信小程序青龙大厅辅助(一贯真的有挂)1、超多福利:超高返利,海量正版游戏,...
重大通报!老k麻将辅助器,we... 重大通报!老k麻将辅助器,wepoker手机插件,必胜教程(果真有挂);是一款可以让一直输的玩家,快...
专业讨论!扣点点脚本辅助器,乐... 专业讨论!扣点点脚本辅助器,乐乐围棋入门插件(确实真的有挂)1、许多玩家不知道乐乐围棋入门插件辅助怎...
分享一款!蜀山四川破解版安卓版... 分享一款!蜀山四川破解版安卓版,wepoker透视app下载,科技教程(真的有挂);亲,有的,ai轻...
玩家攻略推荐!上品游戏辅助器,... 玩家攻略推荐!上品游戏辅助器,小程序家乡大贰脚本(一直是真的有挂)1、下载好小程序家乡大贰脚本正确养...
必知教程!微信小游戏修改器,福... 必知教程!微信小游戏修改器,福建大菠萝万能辅助器,技巧教程(有挂规律);1、点击下载安装,微信小游戏...
总算了解!川南九九辅助,朋友局... 总算了解!川南九九辅助,朋友局辅助器免费版(切实有挂)1、全新机制【朋友局辅助器免费版ai辅助工具激...
推荐一款!时光互娱房卡辅助,w... 推荐一款!时光互娱房卡辅助,wepoker俱乐部辅助,2025教程(有挂攻略);推荐一款!时光互娱房...
带你了解!决战卡五星作弊教程,... 带你了解!决战卡五星作弊教程,百乐盟有没有挂(切实是有挂)1、决战卡五星作弊教程破解器简单,决战卡五...