dart Permission.photos请求无法在我当前的设备上运行

w46czmvw  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(125)

我计划实现一个功能,包括从用户的设备由用户的图像。但不幸的是,它并没有像预期的那样在Flutter应用程序中工作。我做了一些研究,并实现它,但没有完成。以下D/permissions_handler(1361):No permissions found in manifest for:[]9当请求权限时发生
x1c 0d1x的数据

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:snapup/global/string_holder.dart';

class AddItemFromImageScreen extends StatefulWidget {
  final String company, productName;
  final bool isImageInput;
  const AddItemFromImageScreen(
      {Key? key,
      required this.company,
      required this.productName,
      required this.isImageInput})
      : super(key: key);

  @override
  State<AddItemFromImageScreen> createState() => _AddItemFromImageScreenState();
}

class _AddItemFromImageScreenState extends State<AddItemFromImageScreen> {
  final TextEditingController _itemNameController = TextEditingController();
  final TextEditingController _itemDescriptionController =
      TextEditingController();
  final TextEditingController _itemPriceController = TextEditingController();
  final TextEditingController _itemDiscountController = TextEditingController();
  int _currentHorizontalIntValue = 0;
  double _appBarBottomBtnPosition = 28.0, _textInputRad = 15.0;
  bool _isVisible = true;
  String _title = "", _imageUrl = "";
  var _finalImagePath;
  var _context, _dateModified, _dateAded;

  @override
  void initState() {
    if (widget.productName.isEmpty) {
      _fetchProductData();
    }
    _loadPermission();
    super.initState();
  }

  @override
  void dispose() {
    _itemNameController.dispose();
    _itemDescriptionController.dispose();
    _itemPriceController.dispose();
    _itemDiscountController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Theme(
        data: ThemeData(
          // Define the default brightness and colors.
          brightness: Brightness.light,
          primaryColor:
              widget.isImageInput == true ? Colors.red : Colors.orange,
          colorScheme: const ColorScheme.light().copyWith(
            primary: widget.isImageInput == true ? Colors.red : Colors.orange,
            secondary: widget.isImageInput == true ? Colors.red : Colors.orange,
          ),

          // Define the default font family.
          fontFamily: 'Roboto',
        ),
        child: _content());
  }

  _content() {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: !widget.isImageInput
          ? AppBar(
              title: Text(
                _title,
                style: const TextStyle(
                  fontWeight: FontWeight.bold,
                ),
              ),
            )
          : null,
      body: widget.isImageInput
          ? _generateSliverAppBarContent()
          : _generateNormalAppBarContent(),
      floatingActionButton: FloatingActionButton.extended(
        onPressed: () => _pushToCloud(),
        label: Text(
          AppStringHolder.btnSave,
          style: const TextStyle(color: Colors.white),
        ),
        icon: const Icon(
          Icons.save_as_rounded,
          color: Colors.white,
        ),
      ),
    );
  }

  _generateSliverAppBarContent() {}

  _generateNormalAppBarContent() {}

  _pushToCloud() {}

  _fetchProductData() {}

  _loadPermission() async {
    if(await Permission.photos.status != PermissionStatus.granted){
      Permission.photos.request();
    }
  }
}

字符串
我在android menifest中使用以下权限

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>

klh5stk1

klh5stk11#

如果你仔细检查了AndroidManifest文件,并确保你把所有必要的请求,仍然面临这个问题,阅读下面。

D/permissions_handler(1361):在manifest中找不到:[]9的权限,因为您请求的权限是错误的Android SDK级别。

如果设备的Android SDK为32或更低,请要求权限.存储否则,请使用权限.照片
请查看permission_handler包中的文档/注解(第89行)https://github.com/Baseflow/flutter-permission-handler/blob/main/permission_handler_platform_interface/lib/src/permissions.dart
在Flutter中,您可以使用DeviceInfoPlugin. https://pub.dev/packages/device_info_plus检查androidSdkVersion
只是呼唤

if (Platform.isAndroid) {
  final deviceInfo = DeviceInfoPlugin();
  final androidInfo = await deviceInfo.androidInfo;
  final androidSdkVersion = androidInfo.version.sdkInt;
  if (androidSdkVersion >= 33) {
    Permission.photos.request();
  }
}

字符串
应该可以解决这个问题。
不过,我想说的一件事是,错误描述太神秘了。[]9表示

static const photos = Permission._(9);


在软件包的permissions.dart文件夹中。

相关问题