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

相关内容

热门资讯

透视新版!wepoker透视脚... 透视新版!wepoker透视脚本(透视)原来是真的有挂(详细辅助微扑克教程)1、点击下载安装,wep...
指导大家!aapoker发牌逻... 指导大家!aapoker发牌逻辑,哈糖大菠萝软件下载,细节方法(有挂技巧)准备好在哈糖大菠萝软件下载...
透视辅助!德扑圈透视(透视)一... 透视辅助!德扑圈透视(透视)一直真的有挂(详细辅助扑克教程)1、完成的残局,帮助玩家取得所有比赛的胜...
每日必备!德州局hhpoker... 这是一款非常优秀的约局吧游戏挂 ia辅助检测软件,能够让你了解到约局吧游戏挂中牌率当中全部隐藏参数,...
透视了解!wepoker有辅助... 透视了解!wepoker有辅助插件吗(透视)其实有挂(详细辅助详细教程)1、系统规律教程、辅助透视等...
今日百科!wepoker黑侠辅... 《今日百科!wepoker黑侠辅助器正版下载,哈糖大菠萝免费辅助器,可靠教程(有挂技巧)》 wepo...
透视插件!wepoker透视版... 透视插件!wepoker透视版下载(透视)竟然真的有挂(详细辅助力荐教程)1、首先打开wepoker...
盘点一款!wepoker怎么挂... 盘点一款!wepoker怎么挂底牌,德州hhpoker脚本,必赢教程(有挂神器);支持多人共享记分板...
透视美元局!wepoker可以... 透视美元局!wepoker可以透视码(透视)其实存在有挂(详细辅助技巧教程);1、机器人多个强度级别...
必备攻略!we poker插件... 《必备攻略!we poker插件,哈糖大菠萝万能挂,揭秘教程(有挂技巧)》 哈糖大菠萝万能挂软件透明...