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、让任何用户在...
透视脚本!wepoker透视脚... 透视脚本!wepoker透视脚本安卓,hh poker辅助有用吗,可靠教程(都是是有挂);玩家在we...
透视肯定!wepoker免费透... 透视肯定!wepoker免费透视脚本,aapoker怎么选牌,扑克教程(素来是有挂);wepoker...
透视肯定!德普之星怎么作弊,w... 透视肯定!德普之星怎么作弊,wepoker透视app下载,系统教程(真是是真的有挂);支持2-10人...
透视脚本!wepoker辅助透... 透视脚本!wepoker辅助透视软件,pokemmo辅助官网,2025新版(竟然真的是有挂)1、不需...
透视教程!wpk有脚本吗,we... 透视教程!wpk有脚本吗,we-poker辅助器,解密教程(原来真的是有挂)是一款可以让一直输的玩家...
透视智能ai!wepoker脚... 透视智能ai!wepoker脚本,hh poker透视器下载,2025新版教程(竟然是有挂)关于we...
透视工具!hhpoker透视脚... 透视工具!hhpoker透视脚本安卓,hhpoker免费辅助器,介绍教程(原先有挂);(需添加指定Q...
透视了解!wpk辅助软件多少钱... 透视了解!wpk辅助软件多少钱一个,来玩德州破解器,2025新版技巧(竟然真的有挂);科技详细教程Q...
透视挂透视!wpk透视脚本视频... 透视挂透视!wpk透视脚本视频,wejoker辅助器怎么卖,安装教程(一直真的有挂);原来确实真的有...