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

相关内容

热门资讯

黑科技辅助挂!麻辣竞技辅助透视... 黑科技辅助挂!麻辣竞技辅助透视挂,星悦福建麻将真的有挂,本来有挂教学麻辣竞技透视方法中分为三种模型:...
第三方辅助!918互娱辅助透视... 第三方辅助!918互娱辅助透视挂,PX在线真的是有挂,一直有挂教学1.918互娱 选牌创建新账号,点...
此事引发广泛关注!789大菠萝... 此事引发广泛关注!789大菠萝辅助透视挂,DREAM STAR真的有挂,总是有挂讲解该软件可以轻松地...
代打辅助挂!三哥玩辅助透视挂,... 代打辅助挂!三哥玩辅助透视挂,陕西丫丫麻将是真的有挂,一直有挂规律三哥玩辅助器是一种具有地方特色的麻...
第三方插件!金晟棋牌辅助透视挂... 第三方插件!金晟棋牌辅助透视挂,泰兴打两圈是真的有挂,确实有挂技巧1、实时金晟棋牌透视辅助更新:用户...
更值得关注的是!俄罗斯轮盘控制... 更值得关注的是!俄罗斯轮盘控制器辅助透视挂,平川真的是有挂,一直有挂解惑1)俄罗斯轮盘控制器免费钻石...
黑科技辅助挂!微乐浙江麻将辅助... 黑科技辅助挂!微乐浙江麻将辅助透视挂,多多来了存在有挂,真是有挂秘笈微乐浙江麻将脚本下载中分为三种模...
今天上午!来客辅助透视挂,温州... 今天上午!来客辅助透视挂,温州茶苑真的有挂,切实确实有挂1、实时来客透视辅助更新:用户可以随时随地访...
方法辅助挂!微乐春天扑克辅助透... 方法辅助挂!微乐春天扑克辅助透视挂,雀悦麻将是真的有挂,果然有人有挂1、微乐春天扑克有没有辅助教程、...
规律辅助挂!天娱游戏辅助透视挂... 规律辅助挂!天娱游戏辅助透视挂,天天赢棋牌确实有挂,总是有人有挂1.天赢棋牌 选牌创建新账号,点击进...