I want to save downloaded images from a server. I want these images to be accessible only from within the application itself. I don't want the images accessible from anywhere else, i.e. someone can just delete/modify it like if it was on the SD card or from another different application. I'm thinking it would be best if I were to use internal storage, as it is private to my app.
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
are there better options out there?
Internal storage is the best option if you want to keep your files private.
However, on most devices, internal storage is very limited and the users might uninstall your app if you use too much of it (images can be pretty big).
You should look into using the external storage to save images, and possibly encrypting them if you really want to keep them private.
As already mentioned by Raghav this would be a good option, and as said the internal storage is very limited (mostly on older devices), however if you are on a rooted device it will be possible to delete your files anyway. Take into account the limited storage, as people is also making "swap partitions" on their SD cards because internal storage is very limited.
This is is the simplest solution. The other typical solution is to store the image as a blob in the application's database. This will make it completely inaccessable outside of your application. You can do it using the method shown here:
How to store and retrieve a byte array (image data) to and from a SQLite database?
The draw back to this is the relatively small memory space you will be given for your DB (<60MB), so this only works if you have a small number of images.
Related
I would like to create an app where I could save text, image and audio notes to an offline database(without internet connection) and then show them in a list-like layout. Wouldnt like to save the files to internal storage directly.
Its my first time creating mobile app so I need help in choosing the right database for such use case. Any suggestions?
I think you may be confusing some terms.
While you can put all sorts of media in a database. Sometimes it not the most practical solution. It sounds like you might be thinking of file storage, not a database.
Further more, the files have to live somewhere, if not on a external server/database, than they will have to reside locally on the device. Your app will not have a local database service running just so that it can store media files. This would be a lot of overhead and take up a lot of resources.
the first thing to know: the database in android is SQLite, So any other offline database it's just a layer for managing the SQLite database, and It only saves numeric and text data, but you can save any other type like image, audio, array...Ect by creating convertors to save it in the database.
E.g: You can save BitMap-Image type- by converting it to ByteArray-List of 0s and 1s-, then converting the ByteArray to String-Default text type-, then you can save it to the database, and when you want to select the value, just convert by the opposite (String -> ByteArray -> BitMap), So the trick here is to know how to convert between the types.
Now the answer:
the best offline-database is RoomDatabase, the fastest way to create and manage SQLite database, with Room you don't need to build an SQLite database from the scratch, it's going to build it for you, and has a great way to create converters.
but for you as a beginner, standard SQLite is more than enough, if you will see RoomDB more difficult.
I'm developing an Android application but I need some help.
I need to store about 2000 image in high resolution (1024x768 and about 2.5 MB each) and the application must work offline so i can't retrieve them from an online database or from anywhere else. These picture should be stored in the SQLite db inside the application because each one of them are related to a specific product.
I've tried to convert the picture to a Base64 string but the result is too big and the app crash. It works only if it's about 467x300 and 30 KB but it loose all its quality so this is not a good solution.
Hope you have helpful suggestions. Thank you.
The way this problem is typically solved is to not store the images in the database, but rather store a link to them in the database. If you want them to be private, store them in the private app storage location. Getting images from a database is tricky, and editing binary blobs like that can be tricky. It can cause issues in the database, which might cause things to be slower. Also, it's easier to load images from a file than from a database.
Also, you could use BLOB, which allows for storing binary data. SQLite supports that, so...
Here is what I did to handle my high resolution images:
give a unique image id to the image, stored in the database
save the image in the android storage
whenever I need a high res image, get its name from the database. use the name to look up the image from storage.
I'm happy to provide a code example, just let me know.
What I need:
For Android: I need to save data permanently, but also be able to edit (and obviously read) it. This data should NOT be accessible by the user - it can contain things like a highscore, which must not be edited by the user.
My Problem
I would have (and have already) used Internal Storage, but I´m not sure how safe it actually is. Here it says:
You can save files directly on the device's internal storage. By
default, files saved to the internal storage are private to your
application and other applications cannot access them (nor can the
user). When the user uninstalls your application, these files are
removed.
That´s basicly exactly what I need - but is it really safe? Can it be accessed (maybe only read?) through a rooted device? (Or any other way?)
What about SQLite-Databases or Shared Memory? Are they better suited for saving (small amounts of) data?
Also: is it generally recommended to handle "secret" data in a different way internally? (like not saving it (internally) as Integer/String but some kind of encrypted)
Can it be accessed (maybe only read?) through a rooted device?
It can be read from and written to.
it can contain things like a highscore, which must not be edited by the user.
It is the user's data, not yours. It is the user's device, not yours. Hence, the user can edit that data if the user wants, so long as their data is stored on their device.
Now, if you wanted to prevent somebody else from editing that data, then encryption, with a user-supplied password, is a reasonable measure. That would seem unnecessary for a game high score.
Otherwise, if you do not want them editing that data, do not store it on their device.
Using SharedPreferences is what you may want. It saves data in an XML file deep in the caverns of the /data/ directory. The user or other apps can't get there unless the phone has root permissions.
http://developer.android.com/reference/android/content/SharedPreferences.html
No it's not safe, user can modify files on rooted devices and emulator. It's better to use Encryption, but encryption is not 100% safe, In fact experienced geeks can crack your encryption. I suggest saving critical data which should not accessed or manipulate by user on your webserver not on user's devices.
I wonder if there's a possibility to create an android app in java which will be installed on specific memory sectors of phone(not the sd card). So those sectors can be accessed from other app and it can be completely erased(couple times write/erase so it won't be recovarable). Do you have any ideas?
Best Regards,
Martin
If I understand you correctly then I think what you want is not possible.
All downloaded apps are instaleld to /data/app/ or SD card. There is no way to put them anywhere else under normal circumstances.
What you can do however is make MODE_WORLD_ WRITABLE files from within your application. If you do that then other applications will be able to see and manipulate those specific files.
Ive been reading up on where to store my files, and I am still not sure what route I should take. I am writing an application that will store images and pdf's (totaling 300MB or so). I would like the app installed on the internal storage, and then allow the user to store the pdfs and some images on there choice of storage. Is it possible to allow the user to choose which storage they use for those files only even I have this in my manifest:
android:installLocation="internalOnly"
Essentially I would like to have the user choose this when the applications start.
If it is, would I just need to have a flag in application that if the user chose external and if the external storage was available, had enough space, then save files to it. Every time the user opened the app I would check to make sure the files are available. If the users chose internal it would use openFileOutput. Does this all seem right, is this possible?
Or should I just consider making it completely internal only, because without these PDF's and images the app is not usable.
It sounds like you can set the installLocation as following to accomplish exactly what you want:
android:installLocation="preferExternal"
From the documentation:
If you declare "preferExternal", you request that your application be
installed on the external storage, but the system does not guarantee
that your application will be installed on the external storage. If
the external storage is full, the system will install it on the
internal storage. The user can also move your application between the
two locations.
If you set it to internalOnly, the user cannot move the application from internal storage to external storage, so above solution is probably your best option.