do you know how to create a folder in which photos will be saved and os and other apps should see that folder as photo album? I need to save photos in a certain album and if album does not exists, I need to create it.
Thanks
If you store images files anywhere on the external storage (with the exception of locations that also contain a .nomedia file), the media scanner, and thus the built-in "Gallery" app, will locate them and display them.
To be a good citizen you should place such files in the recommended location on the external storage using getExternalStoragePublicDirectory. You can pass that DIRECTORY_PICTURES for images.
Be advised though, that stuff is only available as of API level 8. If you need to also support earlier API versions you can use getExternalStorageDirectory and still use the correct recommended path on your own.
And, as always, you need to make sure the external storage is available before you try to write to it.
Related
Im trying to develop an android-lib to store files in /sdcard/{Environment.DIRECTORY_*} after Android 10 has locked everything with its scoped storage.
I tried context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) which is giving me /sdcard/Android/data/my.company.namespace/files/Pictures. I was assuming I could use the MediaStore to scan this Folder and gallery Apps will show Pictures from there. Unfortunately, It doesn't...
I'm reading the docs for hours, but cannot find a comprehensive guide on how to do this.
For Example:
MediaStore.Images.Media.insertImage(ContentResolver, Bitmap, String, String) is deprecated and links to MediaStore.MediaColumns.IS_PENDING which doesn't say a word on how to use it.
If I look inside the code, It uses a lot of classes which are non-existant, like PendingParamsor PendingSession and even If I copy them they still use deprecated methods.
Is there a comprehensive guide, how to use MediaStore to save Files at their respective locations?
Say I want to store a custom image format (image/wsq) in /sdcard/Pictures. Or a custom binary file in /sdcard/Documents. It doesn't matter if other apps could access it or not.
How do I do it with MediaStore?
My Android app creates a folder on the users device's external storage on launch:
File images = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "rapical" + File.separator);
images.mkdirs();
I have around 16 image icons (.png) that I would like to place in this folder the first time the user opens the app.
What is the best practice to do this? Should I place them in the drawable folder initially and then copy them over to the newly created images folder? Not sure what approach to take!
There are two separate issues here:
What to do with images that the user adds to your app?
What to do with your starter images, for your default foods?
Using external storage for the user-added images has some implications:
Your app can survive that image no longer existing, since the user, or other apps, can delete that file at any point
Your user does not mind that the image will get picked up by other apps, such as photo galleries
Unless you specifically want these images to be user-manipulable outside of your app, I suggest that you use internal storage for the "re-sized, compressed and stored" user-supplied images. The original image might be on external storage (I assume that you are using ACTION_GET_CONTENT and/or ACTION_OPEN_DOCUMENT to get the image), but your modified copy would be private to your app.
I sincerely hope that you are using an image-loading library, like Picasso, for loading these images, since they will handle things like background threads and ListView/RecyclerView image recycling and stuff for you.
In that case, what you store in the SQLite database for your default foods needs to be something that the image-loading library can interpret, to bring in the image that you want.
In that case, I would suggest using assets/ to ship the images and file:///android_asset/... values in the database. file:///android_asset/ points to what amounts to assets/ in your project, so if you have assets/chicken_pad_thai.jpg in the project, Picasso (and any decent image-loading library) would be able to interpret file:///android_asset/chicken_pad_thai.jpg) and load the image.
This saves you from making duplicate copies of the images, saving the user disk space and time on first launch. It also means that if you replace the images in your app (e.g., you get a better photo representing chicken pad thai), the user will start seeing the updated image, without you having to do some extra work to realize that you shipped a new image and have to copy that image out to a file somewhere.
Now, suppose that you really do want the user-supplied images to be on external storage. In that case:
Probably rather than the directory that you chose, I would go with getExternalFilesDir() (a method on Context), as on API Level 19+, you do not need WRITE_EXTERNAL_STORAGE as a permission
If you want the user to be able to manipulate the images of the default foods, then copy those out to that location on first run
I am wondering if there is a built-in feature that does this or if I need to home-roll my own view or use an external library, but let's say I have a designated folder (could be either in internal storage or public/private external storage) and I want to be able to allow the user to view any pictures they have in this folder, select any number of them arbitrarily, delete them if desired, run custom code if a picture is clicked, etc.
You need to design that on your own. There's no in-built file explorer/file manager provided by android APIs.
I need to store the list of downloaded image in device.I need to know what is the best way for storing images.If i store it in sd card when the user removes the sd card from device.In that situation how to overcome this problem.
If you are bothering about the sdCard removal then only on option is available to save on phone memory that is always available.
Or if you have Internet available what about moving to cloud ???
but if the main concern is security of Images you can go with the answer of user #shree202
For the security purpose you can change the extension
Say From JPG ==>> .db
it is use less for other applications and also user manually can't change the extension
and also for more secure way You can encrypt it by changing it to byte.
If you are going to open the images right from your own application, then, you can remove the extension of the image file and then save. After that, while accessing the image you can get the file list and display it again in your application by appending the file extension.
I would like to show a list of files in the Android phone.
For example, i would like my app to be able to list all images stored in the phone, i dont want a gallery view, just a simple list.
I would also like to be able to show all the audio files
any help would be appreciated
Thanks
I'm assuming you mean on external storage. Read up on Data Storage, which will tell you the correct way to go about navigating the file-system.
If you're using API Level 8 or
greater, use getExternalFilesDir() to
open a File that represents the
external storage directory where you
should save your files. This method
takes a type parameter that specifies
the type of subdirectory you want,
such as DIRECTORY_MUSIC and
DIRECTORY_RINGTONES (pass null to
receive the root of your application's
file directory). This method will
create the appropriate directory if
necessary. By specifying the type of
directory, you ensure that the
Android's media scanner will properly
categorize your files in the system
(for example, ringtones are identified
as ringtones and not music). If the
user uninstalls your application, this
directory and all its contents will be
deleted.
If you're using API Level 7 or lower,
use getExternalStorageDirectory(), to
open a File representing the root of
the external storage.
For standard/common media types such as Music, video and images in the internal memory, there are respective ContentProviders in the system that manage them. If you want to build list of such items you should consider querying respective ContentProviders (Google for MediaStore Provider).
However, if you want to build an exhaustive list of all the files in a particular directory, internal or external, you can use File#listFiles() API as was suggested by Fredley above.