Hi Guys I created an app that save URI of images that picked from gallery by the user in the SQLite database, however when I change the location of the images or I delete them my app crushes when try to read them by their URIs from gallery. So I searched in google and I found most people recommend to create an internal file or directory of the app for saving those images but I have no idea how can I create an internal file/directory for my app.
Asked
Active
Viewed 39 times
0
-
https://developer.android.com/training/data-storage/app-specific#internal-access-files – Jake Lee May 05 '21 at 13:23
-
@JakeLee Okay i will check the doc, thank u for the link :) – Mark Lee May 05 '21 at 13:33
-
Saving urls in a file instead of a database makes no difference is the file becomes deleted. You should simply catch the exception that lets you app crash now. – blackapps May 05 '21 at 13:37
-
I think he might be saying he wants to create a dir and copy the images there so he retains them even if the user deleted them? – spartygw May 05 '21 at 13:40
-
@spartygw hah yeah exactly, do you have any idea how to achieve that? – Mark Lee May 05 '21 at 13:55
-
@blackapps I'm trying to do like #spartygw said – Mark Lee May 05 '21 at 13:57
-
I think converting URI to Bitmap will be a solution to saving images in an internal directory? – Mark Lee May 05 '21 at 14:01
-
See here: https://stackoverflow.com/questions/13133579/android-save-a-file-from-an-existing-uri – spartygw May 05 '21 at 14:09
-
@spartygw Thank, but it seems in this case they used external storage not internal – Mark Lee May 05 '21 at 14:14
-
Yeah, just create a folder in your sandbox with `getFilesDir` – spartygw May 05 '21 at 14:16
-
@spartygw as I know it's better to store them in internal storage bcz it's secure and can hold more data than external – Mark Lee May 05 '21 at 14:17
-
`think converting URI to Bitmap will be a solution to saving images in an internal directory?` @Mark Lee. No. Just copy the file. No messing around with bitmaps. Makes no sense. If you would copy a pdf file you would not use a bitmap either. – blackapps May 05 '21 at 15:41
-
@blackapps yeah u're right even though in my case i'm sure i'm not gonna use pdf or videos i think copying them will be the best option – Mark Lee May 05 '21 at 16:49