Is there an iPhone-like Keychain in Android?
Asked Answered
S

4

19

I'm looking for something like the Keychain on the iPhone, but for Android development. Something that gives me the capability to save small key-value pairs that are persistent and unchanged even if the user reinstalls the application.

Is there something like that? Can I use the standard preferences that way?

I would like to achieve a behavior similar to the way it works with games on a PC - writing the save files to another folder so that after deletion and reinstallation the save files are not lost.


Edit:

The bounty ran out without somebody mentioning the accountManager. I just stumbled over it. Would that be a method to achieve the behaviour described by me?

Scleroma answered 9/3, 2010 at 17:58 Comment(0)
H
5

You you use storage on the SD card like Michael Cramer stated ( Let the user know you are storing data :-) ). The data on the SD card is not deleted when the app is removed.

You could on the other hand use a server which stores all the details which can be downloaded as and when required and instead of using a user name use the IMEI of the phone which is unique. That way even if the user reinstalls the OS he will still be able to refetch the settings.

for getting the IMEI you may refer : How to get the device's IMEI/ESN programmatically in android?

Hoecake answered 13/4, 2010 at 14:0 Comment(1)
This is answer from 2010, so i want to warn that this is not acceptable answer now. 1) You should not store files outside your app directory storage (scoped storage android 11). It will be available to everyone. 2) You can not get IMEI on all devices/android versionsKoons
E
1

You have the real thing here:

By integrating Smart Lock for Passwords into your Android app, you can automatically sign users in to your app using the credentials they have saved. Users can save both username-password credentials and federated identity provider credentials.

Integrate Smart Lock for Passwords into your app by using the Credentials API to retrieve saved credentials on sign-in. Use successfully retrieved credentials to sign the user in, or use the Credentials API to rapidly on-board new users by partially completing your app's sign in or sign up form. Prompt users after sign-in or sign-up to store their credentials for future automatic authentication.

https://developers.google.com/identity/smartlock-passwords/android/

Emblaze answered 28/6, 2017 at 11:4 Comment(0)
C
0

Since Android & iPhone-like phones will normally run with a data plan, I would suggest that you save your key-value pairs into a centralized server. When the app goes through the uninstall, followed by an install process, just resync it with your server.

Conradconrade answered 18/3, 2010 at 8:35 Comment(3)
I would like to that but I somehow have to identify the user. I don't want to make the user choose a user name but choose a user id automatically and then use that for resync but this id is also lost after an uninstall...Scleroma
you can identify a phone by IMEI, as Ravi Vyas mentioned. It is most likely a safe assumption that there is a one to one relationship between a phone and a user.Malcolmmalcom
sure except for all the people who like to have the newest phone on the block and sell the old one on ebay because they are not locked in to some strange plansScleroma
M
-3

Yes. Preferences are persistant and will survive a normal application upgrade.

Mira answered 9/3, 2010 at 19:26 Comment(6)
Preferences will not survive a re-install though.Selfexistent
Of course...if you uninstall an app it will remove all associated data. Doing otherwise would require a loose definition of "uninstall".Mira
That is bad... Sometimes you want some things to be able to stay, like savegames, account data etc. The things that also don't get uninstalled if you uninstall desktop applicationsScleroma
Although I disagree with the idea that you would retain data when the user explicitly uninstalls an app, you could write to the SD card explicitly.Mira
@Scleroma you have to remember that you are working on a phone, not a desktop computer. People generally expect that mobile phone applications are more simple than desktop applications, and don't want to worry about cleaning up files your application hides on their deviceMalcolmmalcom
I know but the applications requires to identify the user. But I don't won't them to remeber and create an account it would be easier if I could create an account and save it to the keychainScleroma

© 2022 - 2024 — McMap. All rights reserved.