Android App Preference - android

I have this android app with user login and app settings.
app settings are save in default location com.package_preference.xml
when user logins. he or she can set the app settings like notification. or vibrate.
my problem is when another user logins every app settings set by the last user logged in will be use since it was stored localy.
any ways to handle this issue? or better ways to avoid this problems?
I was thingking saving that file on sqlite but that was a lot of work to do.
or name the preference file like user_id_preference.xml but i dont think this is feasible since app preference are save as com.package_preference.xml

Related

Firebase user preferences as android preferences/settings

I'm developing an Application using Firebase analytics, authentication and DB services.
I need to save some preferences and some settings, related to the user.
Most of them are managed in a "SettingsActivity" which is similar to the sample one provided by Android Studio, but with this configuration if the user changes the device, those preferences are lost.
The app should provide a customizable experience for each user. To achieve this I'd like my preferences to be saved on Firebase insted of in local Preferences.
How can I achieve this without have to change too much my app structure?
EDIT:
Here's an example:
The user download my App on first device (Dev-A), he sign up, then he goes to settings and set first setting from A to B, and second setting from A to D.
Then he decide to download my App on a second device (Dev-B), he log in, then he goes to settings.
On Dev-A, first setting is set to B and second setting is set to D.
On Dev-B, first setting is set to A and second setting is set to A.
You will need to store this information in Firebase Database.
Use the user'd UID you get from Firebase Auth in the Database to store the settings.
The data should be under '/users/{uid}'
This way, you will persist all user specific data across devices. (Since the same UID will be presented to same authentication account)
Check this link in Firebase documentation to set the database security
You should try this library:
A implementation of SharedPreferences which syncs with Firebase database to keep your SharedPreferences in sync between multiple devices of one user and/or to back them up for app re-installs!

Android: Sharing Data between multiple applications

I have a requirement, wherein I have 4 android apps, which are sending notifications to a user, at a fixed time of the day. A user could have one, or more of these apps installed on his phone.
I want only one of the apps(any one) to show this notification to the user, because multiple apps popping up notifications is a bad user experience.
For this I need to share some data across the apps.
I was thinking of a mutex/lock based approach, the problem is, where do I store it?
Problems:
Shared Prefs: I don't know which app wrote the data first, and from which app's context should I read.
SQLite: Same Problem as above and app uninstalls need to be handled and SD card might be missing
Server: Mostly offline app, dont want to add internet permission just for this
I see files at a common location as the only way to store this information.
Is there any better way
As you said that the easiest ways is with file,
I did this before and i too wasn't able to find more easy way.
when you show the notification first time then Just make a new file anywhere which can be common for any app and then check if file is exist.
if it exist then don't show the notification and if not then show and make file again, also remember to delete the file from any of your app when day changed, use AlarmManager for this.
hope it helps.

Creating event in calendar only once when App is installled

I am developing a Application which will create events in calendar. Events should get created only once when my application is installed and opened. I tried with using Shared preferences. But when i clear my app data, shared preferences were also getting cleared.
Please let me know how to do this.
Although Shared preferences is usually used for the use case like yours, but since you wants to be guarded against "Clear Data", You may create an empty file as an alternative.
You can check (before creating a Cal.event) if your file(whose exact name and location is only known to you) exist.
Obviously, there are many situations with this approach against which you need to protect.
1.what if user removes this file?
2.if you chose to save file on SD-card, what if sdcard is removed?
In case, if you do not want to rely on Device and data saved on device, and if your app can communicate with Server, then you can maintain this installation history information "online". Then, invoke a network call to query "installation history" info.
For this method to work, you also needs to track on which device and user, the installation was done previously.

Permanent access to app of dropbox account?

I have an app which links to an dropbox account. I am able to login once and is saves that. But each time it asks whether I want to allow access to the app or not . Is there a way to save this preference as well and provide access to the app permanently ?
Read again https://www.dropbox.com/developers/start/authentication#android especially "Return to your app after user authorization".
After successful .getSession().finishAuthentication() there is AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair() which will give You data, which You should save somewhere for later use (You can use SharedPreferences for this).
In start time of application You have to check existance of this saved data, and if it's there, You don't have to call .startAuthentication() again, instead You should call .setAccessTokenPair(access) with saved data as access (look at top of https://www.dropbox.com/developers/start/files#android ).

one time activity using sqlite

I understand how to create a one time activity that saves to preferences to make the activity appear only once. But can someone show me how to save the "first open" screen to sqlite. I want to prevent users from clearing the data and seeing the screen again.
to clarify
I am looking at a password login tutorial and i want the users to register a password with the app but once the password is set, I want the registration screen removed for security purposes. Can someone please help.
Thanks
Using SQLite as your storage is not going to help.
Android will store your database under /data/data/your.package.name/databases/yourfilename and thus, when a user clears the data for an app, it will remove any databases, along with shared preferences too.

Categories

Resources