Android: Keep internal files after updating app - android

I've seen multiple instances where people claim that updating an Android app does not remove its internal files. However, I'm reading and creating a file using openFileInput() and openFileOutput() respectively, which works fine, until the app is updated where apparently the file can not be read, or is deleted.
As I'm developing a game, I would like to avoid SharedPreferences.
As saving progress is more or less mandatory, would writing to an external location be a better alternative? The user shouldn't although be able to tamper with the file (its a serialisation).
Otherwise, is there a way to keep the internal file after updating? Thanks

Why do you not use an SQLite database for this purpose. Updating the app will leave the database untouched unless you explicitely instruct your app to change or delete it.

Related

How to write to the external storage in android that will be present even after the application is uninstalled?

I am trying to build an application in which user can share media files over internet. Now I am confused that there are lots of functions in the library through which we can get access to files stored in the users storage. I don't know which to use..
In Context#getExternalFilesDir(String) documentation, they insist using Environment.getExternalStoragePublicDirectory() to write media that must be shared with other apps and that must be kept even after uninstall of an app. But in Environment#getExternalStoragePublicDirectory(string) documentation, they say that this method is deprecated, and recommend using alternatives such as Context.getExternalFilesDir(). If that was deprecated in first place, then why did they insist to use that method. What is the reason behind them playing these tricks, I don't understand.
Please suggest me a function that is: not deprecated, should return a directory where I can read and write, media stored there should be visible to other apps, they must not be deleted when user uninstalles this app.
I believe you are looking for Shared Storage.
Android file system and storage changed a lot during this years.
Data and file storage overview

How to add new content to my flutter app on the fly?

My flutter app provides some content (mostly text and graphics, like blog posts, or news) to its users. These contents need to be updated daily. So there will be new texts, images, maybe even videos. Now, the app would be used even when offline, so all the updated contents should be stored somewhere to be accessed later.
Right now, I'm using a SQLite DB to store texts
The images are stored in the Assets folder of the app.
The nature of the program is such that the users won't want to give the app any SD-Card access permission.
So my question is, how can I update the content without updating the whole app or using any SDcard permissions?
Is it possible to write code that downloads the new content and saves them directly in the Assets folder of the app? Can the app then use the files? without them being referenced in "pubspec.YAML" file?
Can I store all the data (even images and videos which are added daily) in my SQLite DB which is located in phone memory?
What is the standard practice for apps that have this kind of content?
You have to use the storage somehow.
In Android, you don't have to ask for storage permission if you want to save data in internal directory for your app which is storage/emulated/0/Android/data/data/your_package_name/ folder. You can try that.
However it has got a downside, if your app is deleted then all the data will also be deleted.

Android: how to identify modified files on sdcard?

My android app is saving some file on the sdcard / external storage. Some of these files may then get modified by the user outside the control of my app.
At a later point I would like to identify which files were modified since they were initially created.
Normally this would be easy: simply check the last modified time. Unfortunately an android bug prevents changing the last modified time of existing files.
How does everybody else work around this problem? Clearly cloud sync apps like Dropbox etc have found a way. Do I really need to calculate a hash for every file just to find out whether it has changed?

Start Android app with files on sdcard or somewhere in the filesystem

I making an application with phonegap/cordova where I need to keep a lot of files up to date. Some files (mainly images) will need to be erased in time, and some new ones will get downloaded. The thing is, in Android, to manipulate those files, it seems I need to have them on the sdcard; so I copy the files the app starts with from my assets folder to the sdcard. It just seems like a waste of memory space.
Do you know if is there anyway I can start with the app having those files the app starts with already inside the sdcard? or at least somewhere I can delete them later?
Thank you.
Files that are delivered to the device as part of your APK will be stored in a form that cannot be modified by your application (other than by updating to a new version of the apk).
If you copy the files out of the APK into the private internal storage area or the external storage area, those copies can be modified, but the originals inside the apk will remain.
The most efficient solution may be to not put these files in your apk, but have your app instead download them separately on the first run, using whatever mechanism you wanted to use to change them in the future.
(Some people object to this feeling that such files are less secure against unauthorized use, but as the contents of an .apk are trivial to extract this is not a strong argument. Needing to maintain a server to download from is a slightly more substantial objection.)
You do not need to store the files on the SD Card. Each app has its own internal storage that is not accessible by any other apps. For more information see the official docs: http://developer.android.com/guide/topics/data/data-storage.html

version control routine on Android for data ?

I'm trying to implement a routine that checks the version of files on the sd card. The app essentially downloads a list of files on the sd card. The files on the server are prone to changes in the future.
How do I manage to check if the app is using the latest file. I thought doing it by forcing the user to reinstall the app and using SharedPrerfernces to store the version of each file, but then when the app is reinstalled the SharedPreferences will be deleted.
Any other way that you can suggest ?
Use the lastModified() method to determine the last time you got the files in question and then check to see if they're older than the ones on the server.

Categories

Resources