Android choose where to install application's data - android

I'm wondering about one thing : I want to ask the user while first install my application where to save the data which will he receive after the first sync - on sd card or phone memory and let him to move the files if he first decide to store them in phone memory,but after that he decide to move them to sd card. My question is, which is the best way to remember his choice and build my logic depending on that. I was thinking about using SharedPreferences to save users choice :
editor.putBoolean("isSdCard",true);
editor.putBoolean("isPhoneMemory", false);
and after that use this booleans everywhere where I need to get the files, to get first the storage and then get the files.
Any other suggestions which will be a better solution in my case?

I don't know much of your App but if the following things apply to your app I may have another solution.
Your App can be move to the SD-Card entirely.
The data that is downloaded temporary, that means if the user wants to delete it it won't harm the app and the user can reload the data later.
It is not important that the user has access to the data via an external file browser
If this is the case get rid of the option. Options are always distracting the user from the main use of the app. Just set your install location to auto and let the user decide where to put your app. Now save the data to the cacheDir of your app.
The pros of this approach are:
The cache will be located on the SD-Card if the app is on the SD-Card and in internal memory if the app is in internal memory.
Furthermore the data is cleanly removed if the user deletes the App. If data is saved on the SD-Card there is no way to delete this data once the app gets deleted by the user.
The user sees how much memory your app is using in the applications setting panel.
If the user needs memory she can delete all files that are declared as not important by you through the applications setting panel without accidentally deleting important files like settings

Related

Secure a variable in android

I have an integer variable in my application which I want to save for future use. Depending on it's value (like when the value is 0), I will be blocking a functionality of my app and will be requesting an in app purchase for the same.
If I save it anywhere in internal storage, it'll be flushed after Clearing Data, and if I save it in external storage, the path of the file can be easily found by decompiling the code, and server based solutions are out of my scope.
I know that a full proof security is almost impossible, and you might be thinking of downvoting my question, but I really need some advise from experts like you so that I can at least achieve maximum security, so that I can somehow figure out that the variable's value has been tampered and in that case I'll reset it to zero.
I think there is no way to secure the variable without the server implementation, so in order to achieve your functionality you can perform following steps.
First you need to check the In App Purchase product status - If it's purchased by user then you need to unlock the next functionality.
If user has not purchased or subscribe using in app purchase then you need to lock the next functionality.
In case if you want to protect stored data from reading you can use encryption to store something in the file and then use it in your application. Yes, somebody can find a path to your data, but it would be hard to read it. Also it's impossible to modify data, only corrupt.
On the other hand, it's better to use internal storage or preferences. And yes, data actually should be cleared by clearing application data. You should create default value at the start of your application, if requeired field is missing, and store it. Nothing should remains on device if user delete application\clears data.

React-native: save data in device memory

I know about asyncStorage. That's not what i need. I want to save some data locally, so if app will be completely deleted and installed again, it should gain access to the stored data. AsyncStorage data being removed along with app itself.
I think you must use a FileSystem to save files in phone storage. Take a look at this library to handle files: https://github.com/johanneslumpe/react-native-fs. Hope it helps.
I dont think anything an app creates can exist after app deletion. If you think about it, why would you want disk space being used up by an app you deleted. Only option I can think of is storing in the cloud: Google Drive, DropBox, etc. or a server you run and user data connected to an account system.
My experience is with iOS, maybe Android has some option for what you want.

Data save for an android app after it uninstall or force data clear from settings

I want to give the user some point when they first install the app (but I want it to device specific). It means if he uninstalls and re-installs he will not get that point again. I have found below methods:
Keep device previous data in shared preferences which will be deleted if I release an updates of the app
Store previous data in sql database but if user clears data from settings it will be lost
Create a file in SDcard store data, saving that file in a folder with .foldername and check the file value, problem is that the user can delete it
Every time the user opens the app it sends device id to server, server will check it is previously stored or not before giving point. Problem is that server maintenance should be avoided.
Other than these 3 methods is there any other method?
Can you suggest me any other way,
or can you please tell me if there is no other method which would be better for 3 and 4?
Variation of 4.
using Google's backup servers, however the user can delete the data through his system settings.

Sqlite Database deleted when I clear data from Application

I have created Sqlite database in app. when I clear data from settings->applications->manage applications the Sqlite db removed. any suggestions to keep sqlite database as it is.
When you press Clear Data from the Android application manager its supposed to remove everything related to the app such as preferences, databases, caches etc the only thing that gets left is the app so when you re-launch it behaves as if it was just installed.
If you want to allow the user to clear the data but keep the database then there should be an option in the menu that removes the shared preferences but doesn't do anything with the database.
Hope this helps.
Android's SQLite is intented for local app data storage. When you opt to wipe your app's data, this data is wiped (as expected).
If you want to persist DB data, look into external storage (eg. the late Parse.com, or MS's Azure). You'll be making network calls, your local data will still be wiped, and you'll need to have a way to link your app back up with the external data post-local-wipe (eg. logging in) but your external data will survive an app data clear.
The "linking up" part can be mitigated as well depending on your use case, eg. Google Play Games' data services is tied to your Google Play id and will resync after an app wipe.
Why would you want to keep the data when the user wants to clear everything.
It is not suggested you keep the db.
I would suggest you use the sd card to store images/text files with the adequate permission from the user.

Difference between "extending Application" and sharedPreferences?

I am looking to store simple variables so that if the app process is stopped the data will still be available when it relaunches. I looked into extending the Application class and sharedPreferences. To me, it seems that extending Application is good for temporary global variables that are deleted when the app process is stopped. sharedPreferences however saves the variable onto a file so that is is always available. What are the differences between the two, and what are their optimal uses? Also, what is the best for storing variables that you want to keep even if the app is stopped?
When your app's process is killed, any data stored in the Application class will be lost. You should only use that for storing data that is not needed across multiple launches and uses of your app.
For storing simple data like highscores, sound preference, showing a dialog at startup preference, your best bet would be SharedPreferences. For more comprehensive data, like a list of purchases made by an user in your app, or notes in a todo list app, you should use an SQLite Database.
Beyond that, if you want to store files like PDFs etc. or images (images can also be saved into a database), you can use the internal storage or the external storage (may be an SD Card, or a partition on the internal storage). Please keep in mind that on most devices, internal storage is very limited and you shouldn't save excessively large file there.
This part of the documentation should help you with storage options.

Categories

Resources