LecleVietnam/LeclePackageIssue

lecle_downloads_path_provider 0.0.2+8 not working in API 33 Android 13

Closed this issue · 15 comments

this plugin is working fine in android 12 but in android 13 returning Permanently Denied

Hi @abhinavsinghring,

Thank you for your feedback, our team will work on this issue asap.

Hi @abhinavsinghring, can you show us the error you received and the device you are using? Thank you.

Hi @abhinavsinghring, can you show us the error you received and the device you are using? Thank you.

I am not getting any error in my code. I'm using 2 devices for debugging one is emulator with Android 13 and other is physical device with Android 12. I'm trying to get storage permission before looking for download directory and it's working fine as its supposed to be but in emulator with Android 13 no dialogue is showing to request permission.

Code

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:lecle_downloads_path_provider/lecle_downloads_path_provider.dart';
import 'package:permission_handler/permission_handler.dart';

import '../widget/medium_text_wo_overflow.dart';

class Downloader extends StatefulWidget {
  const Downloader({Key? key}) : super(key: key);

  @OverRide
  State createState() => _DownloaderState();
}

class _DownloaderState extends State {

  String url = 'https://drive.google.com/uc?export=view&id=1I7_WHVHnoit_Y5ltTWE4Flzsc4smaK0v';
  String progress = '0';

  void startDownloading() async {
    Map<Permission, PermissionStatus> statuses = await [
                            Permission.storage, 
                            //add more permission to request here.
                          ].request();
                          print(statuses[Permission.storage]);

                          if (await Permission.speech.isPermanentlyDenied) {
                              // The user opted to never again see the permission request dialog for this
                              // app. The only way to change the permission's status now is to let the
                              // user manually enable it in the system settings.
                              openAppSettings();
                            }

                          if(statuses[Permission.storage]!.isGranted) {

                            var dir = await DownloadsPath.downloadsDirectory();
                            
                           if(dir != null){

                                      String savename = "neet2020.pdf";
                                      String savePath = dir.path + "/$savename";
                                      print(savePath);
                                      //output:  /storage/emulated/0/Download/banner.png

                                      try {
                                          await Dio().download(
                                              url, 
                                              savePath,
                                              onReceiveProgress: (received, total) {
                                                    if (total != -1) {
                                                      print(
                                                        (received / total * 100).toStringAsFixed(0) + '%'
                                                      );

                                                      setState(() {
                                                        progress = ((received / total) * 100).toInt().toString();
                                                      });
                                                      
                                                    }
                                                },
                                                deleteOnError: true,
                                                
                                                ).then((_) {
                                                  Navigator.pop(context);
                                                }
                                                );
                                                
                                           print("File is saved to download folder.");  
                                     } on DioError catch (e) {
                                       print(e.message);
                                     }
                                }
                            }else{
                               print("No permission to read and write.");
                            }
                            
  }

  @OverRide
  void initState() {
    super.initState();
    startDownloading();
    
  }

  @OverRide
  Widget build(BuildContext context) {
    return AlertDialog(
      backgroundColor: Colors.white,
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          const CircularProgressIndicator.adaptive(),
          const SizedBox(height: 20,),
          MediumText2(text: "Downloading: $progress%",size: 17, color: Colors.black,)
        ],
      ),
    );
  }
} 

Hi @abhinavsinghring, did you mean that the permission dialog didn't appear is because of our package?

  1. If this is true, we think that this is not an issue related to our package because our package is just a simple package that supports for getting the absolute path of the downloads directory (and some other directories on Android).
  2. After checking the issues of the permission_handler package, we have seen that there are a lot of developers are having the same issue on Android 13 like you. Can you check those issues here and tell us if we have misunderstood your issue?

Thank you.

No I'm not saying this is issue with your package but your package isn't working on 13. So any solutions?

Hi @abhinavsinghring, so you mean that you can not receive the path of the downloads directory on Android 13 when using our package, is it right?

Hi @abhinavsinghring, can you tell us the model of the Android emulator that you can not receive the downloads directory path from the package? We will test on that device and find the solution for this issue. Thank you.

Pixel 4 API 33 with Google Play service

Hi @abhinavsinghring, after testing our package on Pixel 4 API 33 with Google Play service we found that we can receive the absolute path of all Android directories (defined in DownloadDirectoryTypes class) and also we can receive the absolute path of the downloads directory even in default use case of the package. So we are not sure what is your problem.

This is the result when we testing on Pixel 4 API 33 with Google Play service

image

Can you please share your complete code. Thank you.

Hi @abhinavsinghring, this is the complete code.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:lecle_downloads_path_provider/lecle_downloads_path_provider.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _downloadsPath = 'Unknown';

  @override
  void initState() {
    super.initState();
    initDownloadsDirectoryPath();
  }

  Future<void> initDownloadsDirectoryPath() async {
    String downloadsPath;
    try {
      downloadsPath = (await DownloadsPath.downloadsDirectory())?.path ??
          "Downloads path doesn't exist";

      // var dirType = DownloadDirectoryTypes.dcim;
      // downloadsPath = (await DownloadsPath.downloadsDirectory(dirType: dirType))?.path ?? "Downloads path doesn't exist";
    } catch (e) {
      downloadsPath = 'Failed to get downloads paths';
    }

    if (!mounted) return;

    setState(() {
      _downloadsPath = downloadsPath;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Downloads path example app'),
          centerTitle: true,
        ),
        body: Center(
          child: Text('Downloads path:\n $_downloadsPath\n',
              textAlign: TextAlign.center),
        ),
      ),
    );
  }
}

Its working now. I found that i hadn't declared Future. Thank you.
The only problem now is that i can't read files from storage. If you have any leads please let me know