如何解决flutter中的“在清单中找不到权限:[]9”

Zan*_*nak 8 dart firebase flutter firebase-storage google-cloud-firestore

我试图制作上传功能,以便用户过去可以将文件上传到 firebase 帐户,它运行良好,但昨天,它不会显示文件

有代码

uploadImage() async {
  final storage = FirebaseStorage.instance;
  final picker = ImagePicker();
  PickedFile? image;

  //Check Permissions
  await Permission.photos.request();

  var permissionStatus = await Permission.photos.status;

  if (permissionStatus.isGranted) {
    //Select Image
    image = await picker.getImage(source: ImageSource.gallery);

    var file = File(image!.path);

    final fileName = basename(file.path);
    final destination = 'user/$emaila/identitas/$fileName';

    if (image != null) {
      //Upload to Firebase
      var snapshot = await storage
          .ref()
          .child(destination)
          .putFile(file)
          .whenComplete(() => null);

      var downloadUrl = await snapshot.ref.getDownloadURL();

      setState(() {
        imageUrlidentitas = downloadUrl;
      });
    } else {
      print('No Path Received');
    }
  } else {
    print('Grant Permissions and try again');
  }
}
Run Code Online (Sandbox Code Playgroud)

这是 Android 清单


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.rekammedis">


    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- Permissions options for the `storage` group -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

    <!-- Permissions options for the `camera` group -->
    <uses-permission android:name="android.permission.CAMERA"/>


   <application
        android:label="rekammedis"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>


Run Code Online (Sandbox Code Playgroud)

编译器说

D/permissions_handler(9318):在清单中找不到权限:[]9 D/permissions_handler(9318):在清单中找不到权限:[]9 I/flutter(9318):授予权限并重试

怎么解决这个问题?有人知道吗?

我尝试在 stackoverflow 中查找,但没有人解释答案

Chr*_*n X 18

这是最近的一个错误,是由 10.2.0 中新版本的权限处理程序引入的。这里讨论了https://github.com/Baseflow/flutter-permission-handler/issues/944,我也会复制这个问题的答案。这个解决方案也对我有用。

当设备为 Android 12.0 或更低版本时,我通过检查 Permissions.storage.status 修复了此问题,否则我使用 Permissions.photos.status。我使用device_info_plus插件来检查Android版本:

我将以下内容添加到我的 AndroidManifest.kt 中

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
Run Code Online (Sandbox Code Playgroud)

并在颤振中:

if (Platform.isAndroid) {
  final androidInfo = await DeviceInfoPlugin().androidInfo;
  if (androidInfo.version.sdkInt <= 32) {
    /// use [Permissions.storage.status]
  }  else {
    /// use [Permissions.photos.status]
  }
}
Run Code Online (Sandbox Code Playgroud)

所有作品均属于 github 上的 HinrikHelga


Cam*_*lli 0

检查文件中的 targetSdkVersion build.gradle

如果您使用的是targetSdkVersion = 30,则需要以不同的方式写入存储权限。我认为你可以尝试这篇文章中讨论的解决方案