Search code examples
javaandroidandroid-afilechooser

How to get access to the default download file path


I'm trying to open my downloaded files on a specific path (my download folder in the app). Unfortunately, I do not know how to implement this method.I found this way by searching the Internet.

 ... } else if (id == R.id.nav_MyDownloads) {
    intent = new Intent(Intent.ACTION_GET_CONTENT);
    Uri uri = Uri.parse("storage/sdcard/pdfs"); // a directory
    intent.setDataAndType(uri, "*/*");
    startActivity(Intent.createChooser(intent, "Open folder"));;

}...

But when I use intent, I see the path of the recent files instead of the path I introduce, please guide me. thank you


Solution

  • Did you tried this to get the directory path ?

    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    

    If I got your question, what you want to achieve is this:

    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    Uri uri = Uri.parse(path.getAbsolutePath());
    

    path.getAbsolutePath() gives you the Download folder path like this: /storage/emulated/0/Download