Permanent Storage in Android after uninstallation of app - android

I am making an application in android. Now the issue which I am facing here is, I want to save one id, which should persist even after uninstallation of app. So is there any way which may fulfill my purpose, and also will be a better idea ? And if yes, Please tell me about the solution.

Place your id in external storage like sdcard in a text file. This will then persist even after uninstallation of application. But the downside is that it is prone to user deletion.

Related

How can I use Android scoped storage to store large app specific files?

I have an old drawing app on Android, which stores drawings (.PNG files) out on a specific folder on external storage. With Scoped Storage in Android 11, I need to find a way to save files, but I can't seem to find a solution that meets my needs. My app has its own gallery UI, like many drawing apps, so that I can control the selection/view UX.
I've tried:
MediaStore: I inserted files with MediaStore. The issue I ran into here is that I couldn't figure out a way to query just the files that my app created. Querying mediastore always returns a bunch of stuff I don't want.
Storage Access Framework. My intuition with this framework, is that I would probably spend a lot of time and potentially regret going down that road. I don't like the idea of not controlling the file selector (gallery). I also don't like relying on intents for a critical part of my app.
MANAGE_EXTERNAL_FILES. Based on the criteria defined by Google, my app wouldn't qualify to use this, though it would be great (since I could keep my old code).
Use internal file storage. I coded this up, and it's really clean, but I hesitate to roll this out, because uninstalling would mean that users lose their documents. Note that i have a Share intent, so users can "export" files one at a time.
What I want:
To write files where they aren't removed when the user uninstalls my app.
To write my files somewhere that the user can back them up one way or another.
Simplicity. I don't want to confuse existing users by changing things drastically.
Am I missing something regarding my options here? Can Mediastore effectively partition my files so that I can show them in the gallery? Does internal storage seem like the best option for me?
Just create your files in the old fashioned way in your apps sub folder in public Documents directory.
No special permissions needed.

Android data persistency

I'd like to develop an app which need some data persistency. For some reason, I don't want to use database. And I'd like something similar to the shared preference. But only have one more requirement:
I hope my data can be persistent across installation. That means even the app uninstalled the data still be stored in Android system safely.
Are there any suggestions? Thanks
P.S.: In iOS, I use the keychain.It works perfectly.
The only solution I can think of to ensure non-removal on uninstallation is to write a file somewhere on the external storage. However this is (a) insecure (b) prone to other issues such as users deleting it.
If you are worried about persisting data on upgrades then using a database with a ContentProvider you can achieve this fairly easily. Shared Prefs are only really meant for a small number of small values/primitives.
There is also the option of storing something remotely, with a web service if it fits with whatever need you have to retain data when uninstalled/reinstalled.
The majority of questions like yours indicate an issue somewhere else in the way your application is architected, if you provide more detail people here may give you a better solution
The only way I can think of doing it is syncing the data with the cloud and restoring it if the user reinstalls the app. You may want to look at leveraging the BackupManager.

Save Object to Internal Storage at Application Install

I would like to know if its possible to save an object at the moment the user is installing the app on mobile.
Why I want this?
My app uses some default objects to his normal behaviour, whenever the user starts the App I want that the objests are there to be used. I could certainly just create them each time the user opens the app..
But that might consume a bit of unnecessary time and performance and battery.. If its default, I want to create only once, and then its always there.
I will also use Internal Storage to create new objects of this type, there will be the default ones, that I described above, and there will be also the option to create new ones and save them to use later, on another time that app is launched, but that its fine, I already read something about how to serialize the object and use internal storage to keep them :)
I am just here asking about the first question, create the item only once at the beginning, maybe on the install moment of the app? I was assuming.. but dont know if its possible.
It has been very helpful to have this space for over an year, I have already learned a lot here from you thank you ;)
Android provides following intent to detect app installation
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
If you use these with conjunction with broadcast receiver you will be notified when user install a new app. Problem with this solution is, it will not help you as you are trying to detect your own app installation.
What you could do is every time user launch your app
check if object exist
if not create one and write it to internal storage.
in this way it will created once. Depend on type of object you are trying to save you might consider using SharedPreferences or SqlLite or simply a file IO. If you are writing Java Object yes serialization is the way to go.
Update
If you are planning to get data from network for the first time, depend on the size you can decide,
Small File: Put it inside Asset folder and ship it with apk.
large file: if the file size is huge you might consider to ship portion with apk and sync and update rest on a background process or download everything from network
I'm not sure what you mean. A Java object exists in memory, so "saving" it when the user installs the app makes little sense. It can't remain in memory unless some process is holding onto it.
If you mean something like a JPEG photo or other data, you can put the data in the directories of your project and then access it as a resource once your app is installed. See the
Providing Resources API guide.

How to maintain data on an android device even if the app is uninstalled?

I want to maintain data on an android device even if my app is uninstalled.
I want to maintain the data (some key) in android device even when the app is uninstalled or removed i want to retain this data when my app is re-installed in the same device.
A similar question passed by on Google Groups quite a while ago and as far as I understood, there's not a single method that will fully prevent a user from deleting the data stored. If you think about it, it actually wouldn't make sense to provide a way to fill up a device's (internal) storage without the user being able to free up that space again.
That being said, your options for storing semi-persistant data that does not get wiped out when an app is being uninstalled seem to be limited to either the SD card, some web-based location or a seperate content provider - each with its own limitations.
You might also want to read through Google's documentation on this.
You can save it to a folder and if app is reinstalled, load it from there.

Blocking access to my app's database

I need to block user access to my app's data stored in the SD card... like the images etc as they are crucial to my app's proper functioning and if deleted by mistake, will cause the application to function way different from what is expected of it. Is there any way to do so programmatically, like when I create this directory structure during my first run, lock the access to it to be only unlocked when the app runs?
Short answer... NO, it's not possible at all.
If it's that important, you could store all your data in a encrypted file. That way if it's deleted then you know it's all deleted and you have to start again. You also know that it's 'most likely' haven't been tampered with.
Most likely tho, the best solution is to handle errors better and become a more robust application.

Categories

Resources