0

My app saves images in a certain directory. How can I open that directory (in a file explorer app) programmatically? I am extending to this question. And I have tried a lot of snippets from the web but nothing works. This is how I am saving images:

class SaveTask extends AsyncTask<Bitmap, Void, File> {

    @Override
    protected File doInBackground(Bitmap... bitmaps) {
        String returnUri = null;
        File outFile = null;
        try {
            outFile = new File(imagesDir, "Draw_Easy " + System.currentTimeMillis() + ".png");
            FileOutputStream outputStream = new FileOutputStream(outFile);
            bitmaps[0].compress(Bitmap.CompressFormat.PNG, 100, outputStream);
            outputStream.flush();
            outputStream.close();
            scanFile(outFile, "image/png");

        } catch (Exception ignored) {
            //TODO: Exception handling
        }
        return outFile;
    }
}

imagesDir.getAbsolutePath() returns /storage/emulated/0/Draw Easy

Shreemaan Abhishek
  • 1,134
  • 1
  • 7
  • 33
  • "How can I open that directory programmatically?" -- what *precisely* do you mean by "open that directory"? Android has never really had that concept, as [we discussed previously](https://stackoverflow.com/a/63754371/115145), but, perhaps I am misunderstanding what you mean by "open that directory". – CommonsWare Sep 05 '20 at 14:26
  • You have already got a complete answer in your other post. So you know by now that it is not possible with ACTION_OPEN_DOCUMENT_TREE and other action if you use a classic file path. But you could do it with a classig file browser/ file picker. Google for such a component. – blackapps Sep 05 '20 at 14:27
  • @CommonsWare "open that directory" means open the directory in which the image was saved – Shreemaan Abhishek Sep 05 '20 at 14:28
  • That was a circular definition. What are you expecting the user to see and for the user to do when you "open that directory"? – CommonsWare Sep 05 '20 at 14:29
  • Untested: https://www.uplabs.com/posts/android-filepicker – blackapps Sep 05 '20 at 14:30
  • you mean you want open or show all the images stored in that directory? you can try 'imageDir.list()' this will give you the array=Array of all the files inside the imageDir. makes sure filter images. then show each image in imageView using 'BitmapFactory.decodeFile("path of the file / array[i])' – Chandresh 204 Sep 05 '20 at 14:46
  • @Chandresh204 I want to open that directory in a flie explorer – Shreemaan Abhishek Sep 05 '20 at 15:02
  • you mean like we do in computer. e.g. when you download a file and then right click on it then open it in a folder and then file manager shows the file. I think its not possible with android because i never seen any app that opens file manager. on your android phone try to download file in chrome then go to downloads, can you see the option show in folder? NO!!!. I also tried the 'Intent.ACTION_VIEW' but that didn't work. I advise you to create a new activity and show all your images in a list view then set on click listener on it and call default imageViewer app to view image – Chandresh 204 Sep 05 '20 at 16:00
  • Does this answer your question? [Android: How to open a specific folder via Intent and show its content in a file browser?](https://stackoverflow.com/questions/17165972/android-how-to-open-a-specific-folder-via-intent-and-show-its-content-in-a-file) – Xid Sep 05 '20 at 16:06

0 Answers0