21

Actually, I need to open the default Download folder from my application. Is it possible? If yes, then please provide some reference.

I am able to get the path of Download folder with the help of:

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

Any help will be well appreciated.

Raghunandan
  • 131,557
  • 25
  • 223
  • 252
abhishek kumar gupta
  • 2,119
  • 6
  • 34
  • 52

3 Answers3

57

You can show the recent downloads activity with the following Intent

startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));

Available since API 9

Ion Aalbers
  • 7,569
  • 3
  • 36
  • 49
  • 1
    Hi Ion Aalbers, thanks for the reply. Is there any way(Intent) to pick the file from Download folder? – abhishek kumar gupta Feb 07 '14 at 09:17
  • @abhishekkumargupta What do you want to do with this file? Open it? – Ion Aalbers Feb 07 '14 at 10:56
  • Hi Ion Aalbers, I want to allow the user to pick the desired file from the Download folder, and upload to the server. Currently I am able to do this task with the help of 3rd party file explorer. – abhishek kumar gupta Feb 10 '14 at 08:02
  • Hello guys. Have you tested that on samsung phones? Because I have tested it with samsung phone (running Nugat) and it was opening a Download Histor but with empty content. The section had not any downloaded file. What I have to do to find my recent download file was to go manually to Samsung Files app and find it under Internal Storage/Downloads. Any idea why that's happening and how can I fix that on Samsung devices? – Tzegenos Jan 15 '18 at 08:12
  • @Tzegenos it is happening because "The Downloads app only shows downloads downloaded via DownloadManager, not all files in the directory", https://stackoverflow.com/a/20472865/5222156 – madim Aug 22 '18 at 11:06
9

Samsung solution:

public static void openDownloads(@NonNull Activity activity) {
    if (isSamsung()) {
        Intent intent = activity.getPackageManager()
                .getLaunchIntentForPackage("com.sec.android.app.myfiles");
        intent.setAction("samsung.myfiles.intent.action.LAUNCH_MY_FILES");
        intent.putExtra("samsung.myfiles.intent.extra.START_PATH", 
                getDownloadsFile().getPath());
        activity.startActivity(intent);
    }
    else activity.startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
}

public static boolean isSamsung() {
    String manufacturer = Build.MANUFACTURER;
    if (manufacturer != null) return manufacturer.toLowerCase().equals("samsung");
    return false;
}

public static File getDownloadsFile() {
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
}

Found by decompiling the Samsung My Files app dex and seeing how the MainActivity deals with intents.

public static final String MYFILES_NOTIFICATION_LAUNCH_INTENT_NAME = "samsung.myfiles.intent.action.LAUNCH_MY_FILES";
public static final String NOTIFICATION_START_PATH = "samsung.myfiles.intent.extra.START_PATH";
public static final String START_PATH = "FOLDERPATH";

if (Constant.MYFILES_NOTIFICATION_LAUNCH_INTENT_NAME.equals(intent.getAction())) {
                String startNotificationPath = intent.getStringExtra(Constant.NOTIFICATION_START_PATH);
                if (startNotificationPath != null) {
                    Bundle newArgument = new Bundle();
                    newArgument.putString(Constant.START_PATH, startNotificationPath);
                    if (new File(startNotificationPath).exists()) {
                        startBrowser(513, newArgument);
                    }
                }
                intent.removeExtra(Constant.NOTIFICATION_START_PATH);
            }
Veedka
  • 368
  • 4
  • 6
  • I've been trying to open folders with the god-forsaken Samsung's FileBrowser App during the last two days. This is the only solution that worked so far. Thanks! – 4gus71n Mar 26 '19 at 04:08
  • You're welcome! I was struggling with it too, longer than I would like to admit. @4gus71n – Veedka Mar 27 '19 at 15:58
1

I had similar problem showing files in Downloads in Samsung and LG and i just added file-parameter "downloaded" for DownloadManager and file showing in Downloads:

  DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
        downloadManager.addCompletedDownload(file.getName(), file.getName(), true,
                "application", file.getPath(), file.length(), true);
Teamothy
  • 1,990
  • 3
  • 13
  • 20