Home > Software engineering >  How to view media files in App-specific storage with default android gallery
How to view media files in App-specific storage with default android gallery

Time:12-07

How can I open the default Android Gallery to display some images that I store in my Application's internal storage folder for example data.com.myapp.appname.files.images?

I have tried a couple of ActivityResultContract but I either get a file explorer to pick media files or i open gallery and i get Access Denied although i have passed authority when creating the Uri.

However, I can successfully view a single picture from the internal storage and if i change the uri to the internal folder it will launch gallery but will just display a blank picture (a null picture with the gray background).

Is it doable at all?

Codes sample:

        val intent = Intent(Intent.ACTION_VIEW)
        .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        .setDataAndType(
            FileProvider.getUriForFile(
                requireContext(),
                "com.company.ApplicationName.provider",
                fileAccessModule.getInternalImagesDir()
            ), "image/*"
        )
    startActivity(intent)

CodePudding user response:

How can I open the default Android Gallery to display some images that I store in my Application's internal storage folder for example data.com.myapp.appname.files.images?

First, there is no single "default Android Gallery". There are hundreds of different gallery-style apps that ship pre-installed across the tens of thousands of Android device models. And, there are many more gallery-style apps that users can install from the Play Store and elsewhere.

None of them will have access to your images. You are placing those images in a location that is private to your app. It is possible that one of these libraries will support private image directories as a data source.

I can successfully view a single picture from the internal storage

You are using FileProvider. That works for files. It does not work for directories.

  • Related