Search code examples
androidfilechooser

Why seeing history in DOWNLOADS folder, but the files are already gone and the files actually there not showing


I am launching a chooser like this (I tried different things as seen in the commented out lines):

Intent intent = new Intent();
//sets the select file to all types of files
intent.setType("application/pdf|application/msword|text/*");
//intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
//intent.addCategory(Intent.CATEGORY_OPENABLE);
//allows to select data and return it
//intent.setAction(Intent.ACTION_GET_CONTENT); // show more 
intent.setAction(Intent.ACTION_OPEN_DOCUMENT); //show less 
activity.startActivityForResult(Intent.createChooser(intent, "Select File"), PICK_FILE_REQUEST);

With this code, the menus showing up is like this:

OPEN FROM

Audio

Recent

Downloads

Galaxy S6 edge

Drive

If I clicking "Downloads" menu, it shows history of files but those files can't be found at all in the phone?

If I browsing into "Galaxy S6 edge" and from there into "Download" folder, I can see the files actually in the phone.

I noticed that the first scenario is "Downloads" with a "s" at the end and the second scenario is "Download".

How can I fix this? Is there a way to programmatically remove the "Downloads" folder appearing in the menu at all?


Solution

  • It seems that using this line of code will show "Internal storage" in the hamburger menu by default:

    intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
    

    It's from this url: How to show the "internal storage" option in an ActionOpenDocument intent by default

    Regarding the "Downloads" history folder: what I observed previously was not accurate. It turned out that the files downloaded into "Download" folder in phone will appear in "Downloads" history folder as well, and when removing the file manually from "Download" folder will not remove it from "Downloads" history folder automatically.

    So it seems like that"Downloads" history folder behaves like a short-cut and it's not cleared automatically when the actual file pointed to is manually removed. This might be most likely an expect behavior. I guess similarly like the short-cut in Windows. Hence, when selecting a file in "Downloads" history folder which has been removed already will generate a NullPointerException as expected and we should handle this exception.