Change username and password of android custom account
Asked Answered
A

3

9

I have created sync adapter for android that syncs data with my server. I works fine, but now I want to be able to change my username and password without removing and adding the account again. How can I do this?

I have a login screen that has edit texts for entering username and password, but how to apply these changes to the account?

EDIT:

Found a way how to change the password:

AccountManager.get(mContext).setPassword(account, password );

where account is my account, and password is the new password.

So now my question is: HOW TO CHANGE THE USERNAME?

Aric answered 26/4, 2013 at 11:30 Comment(0)
A
3

I can change the password with no problem, but if I want to change the username of the account I must delete and recreate the account with the new username. This deletes all data from that account and resyncs the account again from the beginning.

Aric answered 9/5, 2013 at 7:15 Comment(1)
This is true if you use the account name as identical to the username, which, if I understand it correctly, is not required. You could use a different label for identifying the account, and store the username as part of the user data.Prescribe
P
1
AccountManager.renameAccount(Account account, String newName, AccountManagerCallback<Account> callback, Handler handler)

This has been unfortunately added only in API 21 (documentation). In previous versions, deleting and recreating the account with the new username is the only way, as mentioned in another answer.

Pileate answered 19/1, 2017 at 12:22 Comment(0)
T
-1

Use an AccountAuthenticatorActivity, which you can either open from the Settings -> Accounts & Sync page inside your account, or when you try to fetch from the server and get an error indicating wrong login. Look here for details of how to set it up. Writing an Android Sync Provider: Part 1

Timms answered 8/5, 2013 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.