Flutter create file in download folder

612

Based on @blackapps responses, I used the following hard coded path in Android and fallback to getExternalStorageDirectory() if folder didn't exist.

final Directory directory = Directory('/storage/emulated/0/Download');
if (!await directory.exists()) directory = await getExternalStorageDirectory();
Share:
612
Eng
Author by

Eng

Updated on November 26, 2022

Comments

  • Eng
    Eng over 1 year

    In my app I need to download some bills. On IOS my users can easily find them when app is closed because it is stored in a dedicated folder easily findable. I achieve that with getApplicationDocumentsDirectory() from path_provider and the following option in plist :

    <key>UISupportsDocumentBrowser</key>
    <true/>
    

    In android, downloaded files aren't put inside the download folder but inside the app data folder which is hard for a simple user to understand how to go in. What can I do to put bills (pdf) inside the Android Download folder ? I use for the moment the method getExternalStorageDirectory() from path_provider for Android.

    • blackapps
      blackapps about 2 years
      In android, downloaded file aren't put inside the download folder but inside the app data folder No. Who is doing that you said? You can download to public Download or Documents folder and to subfolders of them.
    • Eng
      Eng about 2 years
      @blackapps, I've a Xiaomi : for example files are created inside this folder : /storage/emulated/0/Android/data/my.app.id/files/. I'm looking for a way to put files inside the right download folder, maybe something like /storage/download.
    • blackapps
      blackapps about 2 years
      You are complainig about your code and your code does it. Change it to download to the right storage location. And /storage/download does not exist. I was talking about /storage/emulated/0/Download.
    • Eng
      Eng about 2 years
      I'm looking for a way to get the pathname of the current phone Download folder... I presume Android phone Brands can maybe have a particular download path and not by default /storage/download ?
    • Eng
      Eng about 2 years
      @blackapps /storage/emulated/0/Download is a 'default' path and is common to all Android phone brands ? (Samsung / xiaomi / honor / huawei etc) ?
    • blackapps
      blackapps about 2 years
      Does not have to be that always. Use getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWN‌​LOADS) to get the actual path.