how to access downloads folder in android?

后端 未结 6 1650
陌清茗
陌清茗 2020-11-28 21:08

I am new android, i\'m making an app in which one can download files to downloads folder (using Download Manager). I can see pictures if i go to downloads folder in emulator

相关标签:
6条回答
  • 2020-11-28 21:21

    You need to set this permission in your manifest.xml file

    android.permission.WRITE_EXTERNAL_STORAGE
    
    0 讨论(0)
  • 2020-11-28 21:25

    If you're using a shell, the filepath to the Download (no "s") folder is

    /storage/emulated/0/Download
    
    0 讨论(0)
  • 2020-11-28 21:27

    Updated

    getExternalStoragePublicDirectory() is deprecated.

    To get the download folder from a Fragment,

    val downloadFolder = requireContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
    

    From an Activity,

    val downloadFolder = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
    

    downloadFolder.listFiles() will list the Files.

    downloadFolder?.path will give you the String path of the download folder.

    0 讨论(0)
  • 2020-11-28 21:28

    If you are using Marshmallow, you have to either:

    1. Request permissions at runtime (the user will get to allow or deny the request) or:
    2. The user must go into Settings -> Apps -> {Your App} -> Permissions and grant storage access.

    This is because in Marshmallow, Google completely revamped how permissions work.

    0 讨论(0)
  • 2020-11-28 21:42

    For your first question try

    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); 
    

    (available since API 8)

    To access individual files in this directory use either File.list() or File.listFiles(). Seems that reporting download progress is only possible in notification, see here.

    0 讨论(0)
  • 2020-11-28 21:43

    You should add next permission:

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

    And then here is usages in code:

    val externalFilesDir = context.getExternalFilesDir(DIRECTORY_DOWNLOADS)
    
    0 讨论(0)
提交回复
热议问题