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

相关内容

热门资讯

透视了解!德扑圈透视挂(透视)... 透视了解!德扑圈透视挂(透视)app安卓版破解版(一贯真的有挂);1、德扑圈透视挂ai辅助优化,德扑...
透视ai代打!aapoker透... 透视ai代打!aapoker透视方法(透视)万能辅助器(竟然有挂)aapoker透视方法辅助器中分为...
透视系统!德普辅助器辅助器怎么... 透视系统!德普辅助器辅助器怎么用(透视)透视辅助(一贯有挂);1、德普辅助器辅助器怎么用ai机器人多...
透视有挂!aapoker安装包... 透视有挂!aapoker安装包怎么使用(透视)真的假的(竟然是真的有挂)进入游戏-大厅左侧-新手福利...
透视系统!德普之星app安卓版... 透视系统!德普之星app安卓版破解版(透视)私人局透视(真是存在有挂)1、游戏颠覆性的策略玩法,独创...
透视最新!aapoker辅助插... 透视最新!aapoker辅助插件工具(透视)透视脚本入口(好像是真的有挂)1、任何aapoker辅助...
透视好牌!德普之星透视免费(透... 透视好牌!德普之星透视免费(透视)透视辅助插件(本来真的有挂)1、起透看视 德普之星透视免费透明视辅...
辅助透视!aapoker插件下... 辅助透视!aapoker插件下载(透视)万能辅助器(果然是有挂)aapoker插件下载软件透明挂微扑...
透视脚本!德普之星透视免费(透... 透视脚本!德普之星透视免费(透视)辅助软件(总是真的有挂)1、用户打开应用后不用登录就可以直接使用,...
透视工具!aapoker脚本怎... 透视工具!aapoker脚本怎么用(透视)透视插件(本来是真的有挂)1、任何aapoker脚本怎么用...