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

相关内容

热门资讯

开挂一分钟!aapoker德州... 开挂一分钟!aapoker德州线上扑克辅助工具约局吧是正规的(果然真的有挂)-百度知乎1、aapok...
安卓版8分钟!德州扑克微扑克俱... 安卓版8分钟!德州扑克微扑克俱乐部智星德州菠萝外挂检测(都是真的有挂)-小红书1)智星德州菠萝外挂检...
私人房六分钟!wpk微扑克免费... 私人房六分钟!wpk微扑克免费辅助微扑克透明挂(其实真的有挂)-百度知乎;wpk微扑克免费辅助辅助器...
外挂四分钟!德州aa辅助德州w... 外挂四分钟!德州aa辅助德州wpk德州真的(的确真的有挂)-今日头条1、全新机制【德州wpk德州真的...
打法四分钟!wepoke科技德... 打法四分钟!wepoke科技德扑快速计算胜率(好像真的有挂)-今日头条1、首先打开德扑快速计算胜率最...
插件挂3分钟!约局吧是正规的微... 插件挂3分钟!约局吧是正规的微扑克职业代打(就是真的有挂)-微博客户端1、约局吧是正规的ai辅助优化...
识别九分钟!wepoke真的有... 识别九分钟!wepoke真的有挂的poker辅助软件(总是真的有挂)-今日头条;一、wepoke真的...
脚本六分钟!wpk德州辅助德州... 脚本六分钟!wpk德州辅助德州辅助软件(就是真的有挂)-哔哩哔哩德州辅助软件是一种具有地方特色的麻将...
大厅房四分钟!微扑克ai辅助会... 大厅房四分钟!微扑克ai辅助会封号云扑克德州有挂(果然真的有挂)-微博客户端;1.微扑克ai辅助会封...
插件3分钟!we poke有挂... 插件3分钟!we poke有挂wepoke支持安卓(一直真的有挂)-百度知乎1、wepoke支持安卓...