Change username and password of android custom account - android

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?

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.

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.

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

Related

Changing email in google workspace effect on Firebase auth identity

I had a user of my firebase android app change their email address in google workspace according to these steps to change user email.
My app uses (only) google to sign in:
val cred = GoogleAuthProvider.getCredential(account.idToken, null)
FirebaseAuth.getInstance().signInWithCredential(cred)
After the change the user is able to sign in with their new email and my app still identifies them with the same UID, but when they sign in they still see their old profile pic and their old email which the app retrieves:
FirebaseAuth.getInstance().currentUser?.let { user ->
user.email
user.displayName
user.photoUrl
}
All of those properties still refer to the old email, old profile pic and old display name, but we are mainly concerned about the email property.
I'd like to know why we're still seeing the old email, and is this something that needs to be fixed on the application side or the admin/google workspace side?
Firebase Authentication creates a cached copy of the pertinent information from the OAuth provider when it first creates the account. This information is not updated afterwards, unless you do so yourself with the Admin SDK.

Customize Firebase Reset email content

I am using Firebase in my app and one of the things that I added recently was the option to send a reset password link.
When the user receives the email it looks as follows:
Is there any option to read certain data from my Firebase firestore and display it in the email?
For example, when user1 registered to the app he needed to set an email and a username (say: user1_cool). Now, when user1 sent himself a reset link I had like it to show:
Hello user1_cool,
...
From this link, it seems impossible but still was wondering if someone found a way.
Right now my email is as follows:
<p>Hello %DISPLAY_NAME%,</p>
<p>Follow this link to reset your password for your %EMAIL% account.</p>
<p><a href='%LINK%'>%LINK%</a></p>
<p>If you didn’t ask to reset your password, you can ignore this email.</p>
<p>Thanks,</p>
<p>NeighborBook team</p>
Thank you
Well, as far as I know,
Is there any option to read certain data from my Firebase firestore
and display it in the email?
No, Currently there is no possibility of that in firebase ...
But since you mentioned about user setting a user name I am writing an alternative for this
If you want to show user name in %DISPLAY_NAME% you can modify user display name like this if you want
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName("Custom User Name Goes Here")
.build();
This will modify user display name and when you use the same template for the email the username set by the user will be sent instead of usual display name
Note: This is recommended and should be only used in this
specific case
For more info visit : UserProfileChangeRequest.Builder
You can only change a few things about the emails that Firebase sends, as otherwise this functionality could be abused to deliver irrelevant content.
If you want full control over the emails that are sent, you'll need to implement your own email delivery. You can still use Firebase Authentication's handler for the links in that email, but following the documentation on customizing the email handler.

I Forgot Android Studio Master Password

This might be a little bit silly but I forgot my master password. Even I also forgot when I set the master password.
Every time I want to generate signed APK the Android Studio always asks for master password. What I can do to get my master password again sir?
I also read the thread on stackoverflow here but it doesn't work.
Please help me with this one. I'll appreciate your help.
You can reset password
File -> Setting -> type password in search
click on master password -> leave empty -> click ok (disable password protection)
Now again click master password ->click reset -> enter new password
You can create yourself a new password this time. Read this article to generate a signed apk with your new password.
Now , read this point super carefully, DO TICK THE BOX , that says "Remember password"
just reset master password it will work fine dont bother about that

receive on clear data

Is it possible to receive an event, if the user execute the "Clear Data" on the global app screen?
I create an account in my Application and save the name of the account as preference:
AccountManager accountManager = AccountManager.get(this.context);
Account account = new Account("my account name", "com.mchammer.cantouchthis");
accountManager.addAccountExplicitly(account, "", null);
now, if the user clears the data, the account on the system (used for synchronisation) have to removed too...
thanks for your help
You can't. Your app gets FCed on Clear Data, so you can't run any code.
BUT. You can use SharedPreferences to store a boolean pref, say isAccountInitialized.
You set it to true and store after your AccountManager logic has done creating the account. Then, every time you use the account for sync (or every time you launch your main activity, or your service is up do do something - this you'll have to figure out based on your app specifics) you pull the isAccountInitialized from shared prefs and if it's false and your account is present in AccountManager - that's your sign that user has executed Clear Data and it's time to remove the account from AccountManager. If it's false and there's no account - that's first launch.
// OFFTOP Nice package name :)
It is not possible as As soon as you press clear data. Your application process will be stopped. You can check this link for answer.

Howto let a user change account data in 'Accounts and sync'

There is an existing account on the phone that is used for a sync service. The account has some settings that the user entered when he created the account. Theses settings are stored as user data (--> mAccountManager.addAccountExplicitly(account, mPassword, userData)).
The user should be able to change these settings. How can this be achieved? Do I need a standalone app to change existing account data?
I guess the user would go to 'Settings'/'Accounts and sync'/'myAccount' and should find a menu entry like 'modify account data'. This menu entry should open the same activity that the user has already used to enter the data initially.
Any hints to push me in the right direction?
This fooled me for a while too - I expected to find getUserData()/setUserData() methods on the Account class, but they are on the AccountManager instead:
AccountManager am = AccountManager.get(context);
String myData = am.getUserData(account, SomeClass.MY_DATA_KEY);
myData = "Some New Value";
am.setUserData(account, SomeClass.MY_DATA_KEY, myData);
Check out the AccountManager setUserData method docs for more information.
Cheers, Andrew.

Categories

Resources