skip to Main Content

i was trying to make upload features, so users can upload file into firebase account
in the past, it run well, but yesterday, it wont show the files

there is the code

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');
  }
}

here is android manifest


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


and the compiler says

D/permissions_handler( 9318): No permissions found in manifest for: []9
D/permissions_handler( 9318): No permissions found in manifest for: []9
I/flutter ( 9318): Grant Permissions and try again

how to solve this ? anyone know ?

i try looking in stackoverflow, but none of them are explain the answer

2

Answers


  1. Check your targetSdkVersion in build.gradle file.

    If you are using targetSdkVersion = 30, you will need to write storage permission in a different way. I think you can try the solution discussed in this post

    Login or Signup to reply.
  2. This is a recent bug which was introduced by the new version of the permissionhandler in 10.2.0. It is discussed here https://github.com/Baseflow/flutter-permission-handler/issues/944 and I will copy the answer to this question as well. This solution was also working for me.

    I’ve fixed this by checking for Permissions.storage.status when the device is Android 12.0 or below, else I use the Permissions.photos.status. I use the device_info_plus plugin to check the Android version:

    I added the following to my AndroidManifest.kt

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
            android:maxSdkVersion="32"/>
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
    

    and in flutter:

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

    all credits belong to HinrikHelga on github

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search