What i want is that i have made a picture chooser, the image chosen i then want to save in my own object.
Like i have a class called personalFile, this file then includes all details, name, birthdate etc.. I have made it so i can update this personal file and save them to the external storage getExternalFilesDir() using an ObjectOutPutStream.
Now i have taken a picture of the person, and have browsed my way to the picture and gotten the uri path to the picture, now how do I save this file together with the rest of the information in my class?
I have tried looking but havnt found anyone doing this. The reason is also i'd like to be able to send the personal record to another phone using mms, email or alike and be able to open it there with the picture and all.
One way of doing it (albeit not the most efficient) would be to have a byte[] image; member variable in your class and read the content of your file into that byte array. You are quite likely to experience issues though if the image size is large. The other alternative would be to just copy the image file to your external storage and inside your class simply save the file name of the file. Either way, I'm not sure of the merit of saving images as part of your persistent app data (unless the images are really small).
Related
I have a gallery which is maintained through app and didn't want to give images a jpg extension since I didn't want images to display in phone gallery so users cannot accidentally delete them. Filenames are something like "gall.22", "gall.381", etc. In fact, there are jpeg files.
When I share one or multiple images, they are shared with their filename which is not ending with .jpg and therefore cannot be opened regularly if shared to email, Viber, etc.
Is there a way to share files with a custom name, not the original one (to add just .jpg at the end of filename) and to avoid copying file to another file with wanted name prior sharing?
I didn't want images to display in phone gallery
I think you can try another way instead of rename extension, you can create the folder to store images and create file .nomedia inside this folder. MediaScaner will ignore this folder when scan and you can share image in normal way.
to avoid copying file to another file with wanted name prior sharing
When you share a file by Uri to another app can handle directly by Uri or copy, it depends on another app handle
My app needs to read an image file and store the location in a settings database.
I found how to grab an image using the ACTION_GET_CONTENT intent that opens the media selector. It returns a Uri that looks like content://media/external/images/media/78
I understand this allows saving every kind of data source, not only files. I still have two questions about that.
How is this resolved to an actual file in a folder? Is a database maintained that builds a relation between the number and the very different filename?
If the app wants a local file as a background file for this scenario, should I save this Uri in the preferences or better the real filepath?
Lets say I have an App that allows me to rate mugs. Therefore, I enter some rating criterias, take a Picture of the mug and then save it to a DataBase, to look at it later.
At the moment, I save the picture on a path obtained by
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
and save the path to my SQLite database to look at it later.
This works fine, however, as I rate a hole bunch of mugs all day and change my phone quiet often, I want to be able to backup my App and its data by common Android backup solutions. This works fine with the SQLite Database that holds the data and is stored in App-Context.
But since the database just holds a path to the taken picture (as returned by getExternalFilesDir), the picture is not backed-up. Where do I have to save the picure, to ensure that any common Android backup software will also grap the pictures?
Is it possible to ensure that the path stored in the database is the same, after I put the backup on a new phone? Since it may be possible that the App is located somewhere else on the new phone, absolute paths are not a good idea here... Is it possible to save the picture relative to the App and just save the relative path?
As suggested by greenapps, a possible solution is to save just the relative path of the image in the database. Instead of using
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
I now use
getFilesDir()
to get the app intern folder and save images there. When I want to load the picture I build the path with the same method to get the app dir and the relative path saved in the database.
Is it somehow possible to get a File object from an DocumentFile? With some small trick I can get the real path of the file, but the File class is not allowed to read/write there...
I need to access media files from USB OTG or secondary storage and I need following functions:
get exif data from images => I really need that for
getting the location of the image
getting the real creation date of the image
actually, for displaying purpose, I need all exif data
ability to rotate images (this would be possible by creating a temp image, delete the old one and rename the temp image)
Any idea on how to achieve that?
Is it somehow possible to get a File object from an DocumentFile?
No.
With some small trick I can get the real path of the file
Not reliably. After all, the Storage Access Framework does not require there to be an actual file. Various DocumentProvider implementations work off of cloud services, where the data is not stored locally on the device until needed. Beyond that, whatever approach that you are using is dependent upon internal implementation that may vary by device, let alone Android OS version. And, to top it off, you still cannot necessarily access the data even if you derive a path, as you may not have filesystem access to that location (e.g., files held on internal storage by the DocumentProvider).
get exif data from images
Use the stream, along with EXIF code that can work with streams, such as this one or this one, found by searching the Internet for android exif stream.
ability to rotate images (this would be possible by creating a temp image, delete the old one and rename the temp image)
You don't have a choice to make a local copy, rotate the image, and then write the image back to the original DocumentFile using an OutputStream. Whether that "local copy" is only in RAM, or needs to be an actual file on disk, depends a bit on how you were planning on rotating it.
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.