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真的假的(辅助挂)一贯是真的有挂(真的有挂辅助器)所有人都在同一条线上,像星...
带你了解!聚星ai辅助工具下载... 带你了解!聚星ai辅助工具下载(辅助挂)一直真的有挂(确实有挂辅助攻略)1)免费钻石:进一步探索免费...
记者爆料!wepoker俱乐部... 记者爆料!wepoker俱乐部辅助器(辅助挂)竟然是真的有挂(有挂教程辅助技巧)1、下载好透视辅助下...
必备教程!wpk辅助插件(辅助... 必备教程!wpk辅助插件(辅助挂)本来是有挂(讲解有挂辅助插件)1、许多玩家不知道辅助怎么退出观战2...
一分钟了解!德普之星辅助器怎么... 一分钟了解!德普之星辅助器怎么用(辅助挂)都是是真的有挂(有挂神器辅助技巧)1、在插件功能辅助器技巧...
一分钟教会你!德普之星透视辅助... 一分钟教会你!德普之星透视辅助(辅助挂)本来真的有挂(有挂存在辅助app)1、进入到是否有挂之后,能...
让我来分享经验!aa poke... 让我来分享经验!aa poker辅助(辅助挂)都是有挂(新版有挂辅助插件)1、点击下载安装,脚本分类...
分享认知!wepoker私人局... 分享认知!wepoker私人局辅助(辅助挂)切实真的是有挂(有挂分析辅助脚本)1、首先打开辅助器下载...
一分钟带你了解!hhpoker... 一分钟带你了解!hhpoker透视工具(辅助挂)好像是真的有挂(有挂解惑辅助技巧)一、可以开透视的定...
玩家必看分享!佛手在线大菠萝为... 玩家必看分享!佛手在线大菠萝为什么都输(辅助挂)一直有挂(有挂详细辅助app)1、用户打开应用后不用...