1

When I implement a Photo Picker functionality in my app using Photo Picker Android library. I have access only Camera, Screenshot and Download folders including some recent photos/videos, Not the complete access. But in one of the google implemented app (Snapseed), Same kind of photo picker can access the Intent.ACTION_GET_CONTENT picker to acess other directories after clicking on browse button. For reference I have attached a screenshot

Can anyone please help me, how to achieve the browse button in native android photo picker?

8
  • You have not even mentioned PickVisualMedia() contract. Nor posted your code. Nor mentioned menu.
    – blackapps
    Commented Oct 14, 2023 at 6:12
  • stackoverflow.com/questions/77280010/…
    – blackapps
    Commented Oct 14, 2023 at 6:12
  • Please tell why you think that menu leads to ACTION_GET_CONTENT. Why not ACTION_OPEN_DOCUMENT? Does that menu contain more options? Screenshot?
    – blackapps
    Commented Oct 14, 2023 at 6:41
  • I now see in the Android docs you linked that the menu dots are there in the examples. But i have never seen them.
    – blackapps
    Commented Oct 14, 2023 at 7:16
  • @blackapps I have added photo picker android reference which is very simple to implement, and about ACTION_OPEN_DOCUMENT, I think it is use to open a document throught native intent, GET_CONTENT is use to pick file/content.
    – Rahul
    Commented Oct 14, 2023 at 17:03

1 Answer 1

3

I was able to get the "Browse" option by using ActivityResultContracts.GetContent() instead of ActivityResultContracts.PickVisualMedia(). What this is effectively doing is creating the following Intent:

Intent(Intent.ACTION_GET_CONTENT)
                .addCategory(Intent.CATEGORY_OPENABLE)
                .setType("image/*")

I believe you can launch that intent directly or my code is using the ActivityResultContracts paradigm inside of a composable so it looks like this:

val photoPickerLauncher =
       rememberLauncherForActivityResult(ActivityResultContracts.GetContent()) { uri ->
            //do something with image uri
        }

photoPickerLauncher.launch(MIME_TYPE_IMAGE)

Previously I was using ActivityResultContracts.PickVisualMedia() as outlined in the docs. With that, I wasn't getting the browse option on the photo picker. With the code above, I do. I also tested on an Android 11 device and it works fine using the old gallery UI.

Now I can't really explain why this works so use at your own risk. I find documentation for PhotoPicker and Gallery selection in general very poor. But this seemed to work for me.

2
  • Thanks @Jacosta for this ultimate solution, and I think that this is happening because Android system changes its file management system for an app, If any application having read permission then it can access its own space (Android/media/PACKAGE_NAME) + public directories like (camera, downloads, screenshot). I also don't found any documentation regarding this but It can be the reason.
    – Rahul
    Commented Oct 21, 2023 at 19:56
  • For anyone else the missing code is: private const val MIME_TYPE_IMAGE = "image/*"
    – theJosh
    Commented Jul 9 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.