Update Android Gallery - java

I am developing an Android app which reads images from external storage for image processing, creates a new folder in "pictures" on external storge and stores the processed images in it.
It takes the standard android gallery a long time or even a reboot to recognize the new folder.
Is there a way to update android gallery programmatically so my new folder gets recognized from gallery?

Trigger the mediascanner to read all the media files again. Use this piece of code :
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
This is very inefficient though since it'll begin reading the entire SDCard for changes.

Related

How do you allow file browser apps to access to your app's scoped storage on Android?

As an Android developer targeting Android 12, can you do anything to allow file browser apps on the phone to view the files that your app exports? Google now requires that all apps use "Scoped Storage", which seems to effectively hide the files from file browsers on the phone. So, you can only view them if you plug the phone into a Windows PC and use File Explorer now.
can you do anything to allow file browser apps on the phone to view the files that your app exports
Not if you use an app specific directory like getExternalFilsDir() as the hack that i posted earlier to open the Files app does not work anymore now. Google closed the leak. Google wants ../Android/data/... to be private.
A further possibility is to let the user choose a directory for your files using ACTION_OPEN_DOCUMENT_TREE.
Files will be visible with all file managers.
I know you wait for the best solution an you could find it to be this one..
Normally the Files app on an Android 11 device (started by the user) will not show content of ../Android/data directory.
But if your app starts it with the following code:
StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
List<StorageVolume> volumes = sm.getStorageVolumes();
String uuid = volumes.get(0).getUuid();
String scheme = "content://com.android.externalstorage.documents/document/" + uuid + "%3AAndroid%2Fdata;
Uri uri = Uri.parse(scheme);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(scheme), "vnd.android.document/root");
startActivity(intent );
then it will do.

read/write image file in java on android platform

How do i read an image file and display that image in java onto the android platform. I understand i need to use intents and activities, but i'm not sure how to do it.
Basically i want to make an app on android that reads an image file and then write/display it. This can be done using intents and activities. When the user clicks on the read button, the image file gets read, and then when the user clicks on the write button the image gets displayed.
I'm not sure how to read an image file and then to display that image onto the android platform.

Read image file from SD card on emulator

finally I managed to move some image file to the SD-card on the Android emulator. I have a task to create a application that use a grid layout to show small images, and I guess I should load the thumbnail images from the SD-card and not have the images in the res/drawable-ldpi folder in the project folder and load them from there?! I have also anmount/mount the SD-card on the emulator.
I have a lot of work to do to create this application. Is there a simple way to load on or all the images from the SD-card, just to see if it's working? Thanks!

How to wait for file scanning finished before starting the launcher app

I am currently working on an Android launcher application, and I would like to play some intro video before the launcher starts. Knowing that playing video directly from assets or raw folder does not work on some devices, I include the video file in assets folder, and let the app copy the video file to SD card before playing it.
However, since launcher is always the first application to be started upon bootup, there is a media scanning process right after the bootup. So the problem is when the launcher is started, the SD card file system may still being scanned and not ready to be accessed, therefore the video cannot be played.
Any suggestions and comments are appreciated!
You may copy the file to the stream returned by openFileOutput() and then use openFileInput() to play it.

How do I retrieve the photographs taken by the camera on a phone running Android OS?

I am developing an Android application that retrieves the photographs taken by the phone camera and converts it to an alternative format. How can I retrieve the photograph that has just been shot as well as those that have been shot some time ago but still exists on the phone?
Converting the image format for existing images is just a matter of recursing file storage for images, usually the sd card but not limited to it. As far as hooking into the existing camera application you'll have to review its source to see if that is possible but you can have a service listen for the camera button and start checking for new images to convert. Android does not keep a central database of images or discriminate between "camera" and "other sources" meaning someone or something will have to decide what to convert.
You also may want to consider using the existing camera app as a library and extending it so that you are guaranteed to get the image right after its created.

Categories

Resources