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

相关内容

热门资讯

近日!hhpoker为什么一直... 近日!hhpoker为什么一直输,德扑之星透视辅助插件,一直是有挂(揭秘有挂)1、点击下载安装,德扑...
教学辅助挂!wepoker免费... 教学辅助挂!wepoker免费钻石,智星菠萝可以辅助吗,本来真的是有挂(有人有挂)1、让任何用户在无...
明白辅助挂!wepoker买脚... 明白辅助挂!wepoker买脚本靠谱吗,德普之星透视辅助,好像存在有挂(发现有挂)1、点击下载安装,...
于此同时!hhpoker辅助挂... 于此同时!hhpoker辅助挂是真的吗,德普之星怎么设置埋牌,一直是真的有挂(有挂详情)1、玩家可以...
插件辅助挂!wepoker钻石... 插件辅助挂!wepoker钻石怎么看底牌,智星德州可以透视吗,一贯真的有挂(存在有挂)1、智星德州可...
2026版复盘!wepoker... 2026版复盘!wepoker养号规律,德普之星怎么设置埋牌,本来真的是有挂(揭秘有挂)1)德普之星...
现场直击!wepoker辅助器... 现场直击!wepoker辅助器激活码,德普之星透视辅助软件是真的吗,确实是真的有挂(的确有挂)1、玩...
无独有偶!hhpoker免费辅... 无独有偶!hhpoker免费辅助器,德普辅助软件,其实真的有挂(有挂辅助)小薇(辅助器软件下载)致您...
出乎意料的是!hhpkoer辅... 出乎意料的是!hhpkoer辅助器,德扑之星透视免费,其实真的是有挂(今日头条)1、每一步都需要思考...
黑科技插件!wpk作弊是真的吗... 黑科技插件!wpk作弊是真的吗,德普之星透视辅助软件下载,真是真的是有挂(有挂详细)1.德普之星透视...