Open image aleatory

Hi friends. I did a search here in the group and did not find what I needed. I created an app and would like it to open a random image from my phone’s gallery. I used the Activity Notifier, but I think I’m not setting it right because instead of opening an image, the app is opening the gallery and that’s not what I want. I need the app to open a random image by clicking the button without me having to choose anything. Can someone help me ?

you could use the FileListAsync method from the file extension to get a list of all jpg files of your device


then use the pick a random item block from the list drawer to pick a random image and display it using an image component

Taifun

Thanks for the sugestion. I’ll do it and come back to inform you if it worked.

I would like to thank you for showing the extension that promised to do what I wanted.
After thinking hard and studying the extension, I found out how to do exactly what I wanted thanks to the indicated extension. If there is no problem in displaying the blocks I have assembled, there you have it … opens a random image file and displays the image name correctly using button 1.

Remembering that my device has more than 1000 images and the app didn’t crash and the images didn’t not take quick to load.

to get a list of that amount of images let me suggest you to use the FileListAsync method instead (as already mentioned earlier)
Taifun

But it is working the way I need it. Would you have a way to improve my blocks? I accept criticisms and suggestions without a problem.

yes

Taifun

1 Like

I don’t know how to use this method. Can you help me ?

You are already using FileListAsync method. There’s no need to improve your blocks. :slight_smile:

But the other way I posted it works very well. I was just curious because Taifun said to use the method FileListAsync and I would like to know how.

He is suggesting FileListAsync method which you are already using. Let’s wait for @Taifun to clear the confusion. :sweat_smile:

for a simple use of the FileListAsync method see the Example App “Test FileList blocks” here App Inventor Extensions: File | Pura Vida Apps

do you like to get a list of jpeg and jpg files of the complete device?

Taifun

Hi guys.
After using the extension mentioned by @Taifun , I was able to open a random image. The problem is that in Companion it worked very well, but when compiling the apk and running on the device, the app found nothing. The extension gave an error message that I was unable to execute my random capture command because the list was empty.
After using the FileListAsync method, the app listed not only the images but also temporary files and other files that did not interest me. After thinking a lot, I found a way and I share here my blocks of how I solved this problem. Basically, I specified the exact path from where the images I wanted were and when the extension received the values ​​I set the globalImages variable to receive the values ​​and then added through the so-called FileList, the rest of the images.
I hope it helps those who need it, because when I needed it I was very well helped by everyone. Thanks.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.