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

相关内容

热门资讯

据报道!werplan脚本,w... 据报道!werplan脚本,wepoker免费钻石,练习教程(有挂秘诀)1、操作简单,无需wepok...
最终!impoker辅助,约局... 最终!impoker辅助,约局吧德州透视,大纲教程(有挂透明挂)约局吧德州透视是不是有人用挂微扑克w...
这一问题亟待解决!we-pok... 这一问题亟待解决!we-poker正规吗,wpk透视是真的假的,妙招教程(有挂方略)1、下载好wpk...
第三方辅助!wepoker透视... 第三方辅助!wepoker透视脚本苹果版,wepoker轻量版透视方法,窍门教程(有挂秘诀)1、上手...
现就发布提示!德扑圈透视,aa... 现就发布提示!德扑圈透视,aa poker辅助包,指南教程(有挂详情)1、现就发布提示!德扑圈透视,...
此事迅速冲上热搜!hhpoke... 此事迅速冲上热搜!hhpoker软件可以玩吗,wpk作弊最怕三个东西,窍门教程(有挂规律)wpk作弊...
此事迅速冲上热搜!aapoke... 此事迅速冲上热搜!aapoker辅助器是真的吗,hhpoker视频巡查真的假的,绝活教程(发现有挂)...
刚刚!wpk德州局怎么透视,约... 刚刚!wpk德州局怎么透视,约局吧德州透视,资料教程(有挂秘诀)一、wpk德州局怎么透视可以开透视的...
据权威媒体报道!来玩德州破解器... 据权威媒体报道!来玩德州破解器,佛手大菠萝辅助,技法教程(揭秘有挂)1、在佛手大菠萝辅助插件功能辅助...
2026版总结!wepoker... 2026版总结!wepoker辅助器安装包定制,hhpoker到底可以作弊吗,操作教程(有挂解密)1...