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怎么获得好牌这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很...
玩家攻略!wpk插件,德普之星... 您好,玩家攻略!wpk插件,德普之星到底有没有透视挂脚本(原来真的是有透视)这款游戏可以开挂的,确实...
查到实测!德扑之星怎么开辅助,... 查到实测!德扑之星怎么开辅助,德扑之星怎么开挂安装(都是真的是有开挂)AI 是一款可以让一直输的玩家...
分辨真假!wepoker辅助工... 很多人使用云端 AI 时,都担心wepoker辅助工具、内部资料上传带来隐私风险。这款本地运行的 A...
发现玩家!WPK作弊,德扑之星... 您好:WPK作弊这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别好...
规律教程!wepokerplu... 规律教程!wepokerplus作弊,德扑之星是不是有挂教程(切实是有开挂)AI 是一款可以让一直输...
一分钟揭秘!如何下载德普之星辅... 如何下载德普之星辅助软件AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏攻略...
可靠教程!wepoker辅助器... 可靠教程!wepoker辅助器激活码,微扑克怎么开挂助手(一直是有辅助挂)主打本地运行的 AI 黑科...
每日必备!!wpk刷入池率脚本... 您好,每日必备!!wpk刷入池率脚本,德扑之星开挂脚本教程(先前真的是有透视挂)这款游戏可以开挂的,...
分享给玩家!wepoker手机... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...