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分析,sohoo竞技联盟辅助器,练习教程(有挂技巧)-哔哩哔哩1、sohoo...
必备透视!sohoopoker... 必备透视!sohoopoker辅助!总是一直都是有辅助方法(有挂方法)-哔哩哔哩1、很好的工具软件,...
总结透视!哈糖大菠萝有没有挂,... 总结透视!哈糖大菠萝有没有挂,pokemmo手机脚本辅助器,诀窍教程(证实有挂)-哔哩哔哩pokem...
专业透视!pokemmo辅助官... 专业透视!pokemmo辅助官网!其实是真的有辅助软件(有挂秘笈)-哔哩哔哩1、专业透视!pokem...
了解透视!佛手在线是不是有挂,... 了解透视!佛手在线是不是有挂,德普之星app安卓版破解版,办法教程(有挂功能)-哔哩哔哩1、下载好德...
揭露透视!哈糖大菠萝破解器!一... 揭露透视!哈糖大菠萝破解器!一贯一直总是有辅助方法(有挂神器)-哔哩哔哩1、哈糖大菠萝破解器脚本辅助...
教你透视!wepoker私局代... 教你透视!wepoker私局代打,wepoker私人局俱乐部怎么进,要领教程(有挂头条)-哔哩哔哩运...
详情透视!agpoker辅助!... 详情透视!agpoker辅助!切实是有辅助教程(有挂教程)-哔哩哔哩1、上手简单,内置详细流程视频教...
了解透视!大菠萝789辅助器下... 了解透视!大菠萝789辅助器下载,wpk透视辅助下载,妙招教程(有挂详细)-哔哩哔哩所有人都在同一条...
分享透视!pokemmo辅助脚... 分享透视!pokemmo辅助脚本!其实真的有辅助方法(揭秘有挂)-哔哩哔哩1)pokemmo辅助脚本...