Open a directory

3

I'm developing an application that when I click on a button it exports all my database to an excel file, this file is inside a folder created by the application itself, this created folder is in the internal memory of the device. My question is, if I put a button I can open this folder so I can view the files?

I tried something like this to try to open the folder that contains the files, but I did not succeed.

Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory() + 
                  "/DSS_DIGITAL/");
Intent dss_digital = new Intent(Intent.ACTION_GET_CONTENT);
dss_digital.setDataAndType(selectedUri, "resource/folder");
startActivity(dss_digital);

Thanks to anyone who can help.

    
asked by anonymous 06.06.2018 / 13:14

1 answer

3

To view the device files, you need a file manager. Smart smartphones do not always come with this manager, in which most of the time, each person downloads his or her favorite, such as ASTRO or the #, and others .

I'll try to give a basic example using the ES File Explorer File Manager (already installed on the device), where package is com.estrongs.android.pop . In this way, you just need to use the setPackage method to open it. So you pass the file address using putExtra like this: Uri.fromFile(new File(filePath) . See below how it would look:

Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("*/*");
intent.setPackage("com.estrongs.android.pop");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)));

startActivity(shareIntent);

Note: If the management application is not installed, just check first so that the user can install it. See here this answer with a few tips.

If you do not know the package name of the file management app, one way is to look it up on Google Play and watch the URL. See:

    
06.06.2018 / 15:29