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破解器(透视)wepoker公共底牌(一直一直都是有挂)-哔哩哔哩1、wep...
透视脚本!wepoker有机器... 透视脚本!wepoker有机器人吗(透视)wepoker私局代打(切实一直都是有脚本)-哔哩哔哩1、...
透视工具!德普之星透视辅助软件... 透视工具!德普之星透视辅助软件激活码(透视)德普辅助软件(果然存在有脚本)-哔哩哔哩1、首先打开德普...
透视app!wepoker买钻... 透视app!wepoker买钻石有用吗(透视)wepoker辅助器安装包(都是存在有透视)-哔哩哔哩...
透视神器!wepoker手机版... 透视神器!wepoker手机版透视脚本(透视)wepoker辅助工具(竟然一直都是有透视)-哔哩哔哩...
透视教程!wepoker免费脚... 透视教程!wepoker免费脚本(透视)wepoker免费辅助器(总是有挂)-哔哩哔哩1、玩家可以在...
透视app!wepokerpl... 透视app!wepokerplus作必弊(透视)wepoker透视是真的吗(真是有脚本)-哔哩哔哩一...
透视工具!德扑之心免费透视(透... 透视工具!德扑之心免费透视(透视)德普之星怎么开辅助(果然一直都是有脚本)-哔哩哔哩1、德普之星怎么...
透视app!wepoker线上... 透视app!wepoker线上大神(透视)黑侠破解wepoker(都是是有辅助器)-哔哩哔哩1.黑侠...
透视方法!hhpoker作必弊... 透视方法!hhpoker作必弊码怎么用(透视)hhpoker透视脚本下载(一贯真的有挂)-哔哩哔哩1...