Open a directory

Asked

Viewed 109 times

3

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

I tried something like this to try to open the folder containing the files, but 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);

I thank anyone who can help.

  • What happens is that to view the files from the device, you need a file manager. Smartphones do not always come with file manager, in which most of the time, each person downloads their favorite, as the SUPERSTAR or the ES File Explorer File Manager, and others. Maybe what you can do is try to check if some of them are possible to pass parameters to suggest to the user the installation of a manager.

  • Got it, more I would suggest an app type, pass his package there if this app requires open and if not the app request the installation?

  • If it is possible the friend could show me some code to see how it works. I thank you already.

1 answer

3

To view the files from the device, you need a file manager. Not always the smartphones comes with this manager, in which most of the time, each person low their favorite, as the SUPERSTAR or the ES File Explorer File Manager, and others.

I will try to give a basic example using the ES File Explorer File Manager (already installed on the device), where the package is com.estrongs.android.pop. This way just use the method setPackage to open it. Thus, you pass the address of the file using the putExtra in this way: 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);

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

If you don’t know the name of the file management app package, one way is to search for it in Google Play and watch the URL. See:

inserir a descrição da imagem aqui

  • more have as I point straight to my directory?

  • type: com.estrongs.android.pop/SDCARD/MEU_DIRETORIO

Browser other questions tagged

You are not signed in. Login or sign up in order to post.