I am developing an Android app. This app stores preferences (user settings) relative to its functioning, such as preferred image quality, etc. etc.. And purchases too.
My question is: How to store these settings in Android in a way that they remain persistent even if the application is removed.
Specifically purchases. I want the user to be able to purchase an in-app feature, uninstall the app, and if he reinstalls the app and presses a "Restore Purchases" button, the previously purchased feature will be restored.
I am currently using Android's SharedPreferences to store these settings. I would like some comment on if this will work for my purpose or not.
If you use shared preferences, it will not work. We can't store data permanently using the shared preferences. The best way is using a web service as a backend.
The short answer for your specific case is to use the "managed by user account" purchase type when you set up in-app billing.
Regarding the general case, your app's SharedPreferences are deleted when your app is uninstalled, so no, this will not work. The only data that is kept around after uninstallation is that stored in a public directory in external storage (usually but not always an SD card). Your app's private directory on external storage is deleted, along with your databases, SharedPreferences, etc. during uninstallation.
It would be in poor form (and not very reliable) to use a public area of external storage to try to save user data for this purpose. The correct solution to the general problem of storing user data across devices or uninstall/reinstall cycles is, as #anoop suggested, to send it to a server.
Related
I am developing an app using cordova (currently only releasing on Android) and I am struggling with storage options.
I am currently using Local Storage which seems to work well, however all data/values are wiped if the user uninstalls and reinstalls the app. I was wondering if there is a plugin or some way to permanently store data on Android even if the user uninstalls the app?
The reason I would like this is to allow the user to keep the coins they have earned/purchased if they were to remove the app and then get it back at a later date? I also have an 'ad free' IAP and I am currently storing a value in Local Storage when the user purchases this so don't want the ads to come back if they uninstall/reinstall.
If this is not possible is there an alternative way to recognise if the user has purchased the Ad Free IAP so they will always have no ads?
You could use cordova-plugin-cloud-settings to persist key/value data between installs / across same-platform devices.
You can save user data online. Check Firebase
Fetch the data from the server when needed.
Or you can also write it on a file and save it on local storage (not a good idea for most of the time)
This is terrible practice. You should always keep server side the amount of earned/purchased items then fetch them as you start the app. It wouldn't be too hard to download and rebuild your app in debug mode then change the local storage.
Auto Backup for Apps automatically backs up a user's data from apps that target and run on Android 6.0 (API level 23) or later.
I've a specific SharedPreferences data that I want to automatically back-up, but not all SharedPreferences. Is that possible to do?
Problem: I save an information about user on how much times he has opened application. I'd love to save this number on cloud, because, alot of users nowadays go to Google Play Store and update an existing application following (Uninstall -> Install). Well, as for now, my allowBackup=false, which means, that whenever user uninstalls app, the crucial information about user and his application opening count is lost. If I set allowBackup=true then I keep saving unnesassary data. Is there a possibility to save on the cloud part of SharedPreferences (not everything)? Is there other alternatives?
How to check if the app is a fresh installation or a re installation. I want the user to have his history downloaded if its a re-installation like whats app. I thought of writing the user id in the shared preference but that is not possible as the data may get erased once the app is uninstalled. I am already having a folder of my app on the device which is used for image caching and downloading new images, but this is not reliable as the user may delete the folder. What else can I try ???
Obtain the user storage with getExternStorage, then leave a file there that specifies the usage history. The file you save there will survive uninstalls and reinstalls. Of course the user can delete that file but generally they will not, and if you name it properly they will realize it is part of a program.
I'd suggest you integrate with Android's Backup Service.
People switch phone every two years. Some factory reset their device. Some have more than one device. And some share their device with their kids. Linking a user history so that it follows a particular google account is the ideal way to go.
As to your question regarding Facebook integration, I'm afraid I know too little about that topic to be of any help.
I want to store a small amount of data in a way where it persists between application installs. I obviously can't use SharedPreferences as they are removes upon uninstallation. Is there any way to store data so it survives a reinstall of the app?
The data I want to store is a unique ID, to allow blocking of users of the app if they misbehave. If I cannot store an ID, can I access the Google account(s) email addresses to use them as an indicator?
This blog post makes it clear none of the IDs the OS produces are any good, especially when considering tablets
Android: Identifying app installations
You can store the data in shared preferences and use a backup manager to have them backed up automatically. They should be restored once the app is reinstalled.
There is no real way of blocking the app for certain persons. You could fore all your users to create an account to use the app and block the accounts but they always can recreate an account. You could store something on the SD-Card and check for it but malicious users can find that and delete it. You could try to get the user to authenticate themselves with their google account against your app (andlytics is using an authentication method like that) but the user can factory reset his phone and create a new google account.
You have to choose how important the blocking of the users is and how much you want to annoy your other users because of some users that are not using your app as intended.
yes. you can store some data in the internal memory or the sd card.this can be done by creating(.somename)folder which is invisible to user and create a file.txt to store the data.
If the app is removed, the data is removed. You could put something on the SD card, but there's no reason to believe it would stay there. You might be able to work something through the application licensing mechanism. Details here
I want to save some info regarding a trial version an application.
I want this info to be persistent in order to detect if the user removed the application and installed it again after the trial expiry.
what is the best place to store such info
thanks
Most of the times the solution to this problem is to keep an server side check,
But if you dont want to involve a server its better to give some limited functionality in your trail app and full in the paid version.
There are other methods too like Time Trial but again they all depends on persistent data so they also fails if the user uninstalls and installs again your applucation
Store it in external file.
it wont be deleted after user uninstalled the app.
but
Serverside check by Device ID is the good way ..
I'm working on the same "problem" at the moment (offline solution for trial time expired apps):
My findings: There is no way to ensure that a user never can reinstall & reuse a (time) trial app but there is a way to 'nearly' prevent it:
Use shared preferences / a database / file saved on internal storage containing the install timestamp.
If the device has an external storage card (most devices have) also save the timestamp on the sd card.
The only possiblity to use your application also after expiring is if the user 1. clears app data on the phone and 2. finds the timestamp file on the sd card and also kills this one.
If he "just kills" the first or second check the killed one can be restored on next app start.