I have a notification displaying progress of downloading a file. Upon completion, tapping on it should open the directory in which the file was saved (my app's external storage directory). The intent is set up in the following way and is later passed to a PendingIntent.
val dir = getExternalFilesDir("storage")
val intent = Intent(Intent.ACTION_VIEW)
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
intent.data = FileProvider.getUriForFile(context, authority, dir)
intent.type = DocumentsContract.Document.MIME_TYPE_DIR
What actually happens - the file explorer opens, but shows "Recent" directory(?) instead.
What else I tried:
- passing absolute path instead of content URI, but it makes no difference
- setting type to "/", it then presents a choice on which app to open the dir with, but the result is ultimately the same - "Recent"
- using ACTION_OPEN_DOCUMENT intent instead, to see if it also has the same problem, and yes, it also points to "Recent"
Note: FileProvider is set up just fine, the uri passed to the intent's data is correct. Also note: I want to avoid saving those files to "Downloads", if possible.
That has never been a feature of Android.
FileProviderdoes not support directories.ACTION_VIEWdoes not support directories by default, though some file managers might.DocumentsContracthas nothing to do withFileProvider.That should crash your app with a
FileUriExposedException.