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

相关内容

热门资讯

开挂透视!智星菠萝可以辅助吗!... 开挂透视!智星菠萝可以辅助吗!切实是有辅助攻略(有挂助手)-哔哩哔哩1、智星菠萝可以辅助吗辅助器安装...
详细透视!hhpoker底牌透... 详细透视!hhpoker底牌透视脚本,wepoker辅助器下载,法子教程(有挂详情)-哔哩哔哩1、在...
总结透视!pokerworld... 总结透视!pokerworld修改器,hhpoker的辅助是真的吗,手册教程(有挂方法)-哔哩哔哩1...
专业透视!pokemmo手机辅... 专业透视!pokemmo手机辅助软件!好像存在有辅助软件(有挂讲解)-哔哩哔哩1、下载好pokemm...
分享透视!拱趴大菠萝有挂吗,w... 分享透视!拱趴大菠萝有挂吗,wepoker可以开透视吗,举措教程(有挂头条)-哔哩哔哩;1、wepo...
辅助透视!福建大菠萝万能辅助器... 辅助透视!福建大菠萝万能辅助器!原来是有辅助app(有挂透视)-哔哩哔哩1、福建大菠萝万能辅助器辅助...
详细透视!德州局透视脚本下载安... 详细透视!德州局透视脚本下载安装最新版本,德普之星app安卓版破解版,绝活教程(有挂秘籍)-哔哩哔哩...
曝光透视!拱趴大菠萝挂!确实一... 曝光透视!拱趴大菠萝挂!确实一直都是有辅助技巧(有人有挂)-哔哩哔哩拱趴大菠萝挂破解侠是真的助透视。...
解迷透视!wejoker私人辅... 解迷透视!wejoker私人辅助软件,智星菠萝有挂吗,手段教程(有挂讲解)-哔哩哔哩1、wejoke...
解迷透视!拱趴游戏破解器!竟然... 解迷透视!拱趴游戏破解器!竟然是真的有辅助脚本(有挂细节)-哔哩哔哩一、拱趴游戏破解器游戏安装教程牌...