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.
Related
I was using Firebase Auth Gmail Authentication. While doing some random tests on the app, I deleted the account from Firebase Auth Console while I was still logged in.
Now even if I uninstall the App and reinstall it, I still get the UID even though that UID is not present in the Firebase Auth Console. The first lines of code as soon as I open the app are as follows:
val uidz = FirebaseAuth.getInstance().currentUser?.uid.toString()
Log.d("uid as soon as i open the app",uidz)
Logcat Reads as
2022-09-27 21:40:01.802 23060-23060/com.example.alliaiseV1 D/uid as soon as i open the app: uZOs2XhBOrX4YU8qKem3lD4C7cy1
Strange parts:
This UID if I navigate to some other page and re-check the current user changes to null
Every time I uninstall and reinstall the App I see the same UID every time
It only happens on my device for every other device when I re-install the App the current UID returns as null but for my device, it returns as the above in logcat
Deleting App Data and Cache works but again if I reinstall I see the UID
I edited the code to :
val uidz = FirebaseAuth.getInstance().currentUser?.uid.toString()
Log.d("uid as soon as i open the app",uidz)
FirebaseAuth.getInstance().signOut()
Log.d("uidlogout", "${FirebaseAuth.getInstance().currentUser?.uid.toString()}")
The logcat I read for it is as follows :
2022-09-27 21:45:06.228 23964-23964/com.example.alliaiseV1 D/uid as soon as I open the app: uZOs2XhBOrX4YU8qKem3lD4C7cy1
2022-09-27 21:45:06.229 23964-23964/com.example.alliaiseV1 D/uidlogout: null
From where is this UID coming?
Why do I see the same UID every time?
How do I get rid of it?
While doing some random tests on the app, I deleted the account from Firebase Auth Console while I was still logged in. Now even if I uninstall the App and reinstall it, I still get the UID even though that UID is not present in the Firebase Auth Console.
If you accidentally deleted a user account from the Firebase console it doesn't mean that the current token automatically expires for that account. No, the current tokens will remain valid until it expires. If you however are interested in changing the expiration interval, please note that this option is available in your Firebase console.
If you want to force a user to sign out, then you can use FirebaseAuth#signOut() method, which:
Signs out the current user and clears it from the disk cache.
To prevent that from happening, you should consider creating authorization rules. In this way, you'll be able to differentiate users with valid tokens from the ones that have deleted accounts. If you are using, for example, the Realtime Database to keep a user's data, then you can check whether that user still exists in your security rules using the following line of code:
root.child('users').child(auth.uid).exists()
For more info, I recommend you read David East's answer in the following post:
Deletion of User in firebase does not trigger onAuth method
For FirebaseCrashlytics i am setting the user id once user logged in then store its credentials in sharedpreference.
FirebaseCrashlytics.getInstance().setUserId("12345");
On next App launch User will be automatically logged in. So Should I set user id on every app launch or its the one time function call. What should I do in case on user logged out and switch to another account on same device
You will have to implement a method to associate User ID's with devices/users. You can do something like this UUID uuid = UUID.randomUUID();, to associate randomized UUID's to the setUserId method. You can read more about this here https://www.baeldung.com/java-uuid.
Depending on your method, you can log certain identifiable information based on how your user logs into your app. Such as via email or something, but that's discouraged for privacy reasons.
I have an Android app, which the user can link to Spotify, with :
AuthenticationClient.openLoginActivity(getActivity(), SPOTIFY_REQUEST_CODE, request);
The problem is that I want the user to change his Spotify account so I want to logout the user from Spotify to log with another account. But the data of the connection are saved in the cache and when I use this line again :
"AuthenticationClient.openLoginActivity(getActivity(), SPOTIFY_REQUEST_CODE, request);", it does not show the connection dialog because the user is already connected.
In the doc, it says :
"To log out and clear all stored tokens, use the AuthenticationClient#clearCookies method. Both Spotify and Facebook tokens will be removed."
But the method clearCookies does not exist anymore. What can I do to logout the user and allow him to connect on another account ?
I've searched on the net and seems that this code
AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID, type, redirectUri)
.setShowDialog(true)
.setScopes(scopes).build();
took from this post it's your only choice to try to logout a user.
I can't test it, so you should try it yourself and see if works.
The documentation on the Spotify Android SDK is outdated and is not reflecting the new Spotify auth library on GitHub.
Spotify's Android SDK documentation is definitely outdated. My observation is that when you call
AuthorizationClient.clearCookies(context)
directly before starting Spotify's auth activity, it just works fine. But if you call it once and then expect that the user is logged out, when you start the activity later in the future, cached credentials keep messing around.
I do not prefer
builder.setScopes(arrayOf("")).setShowDialog(false).build()
as it shows you a "not you? Click to log out" option. So basically you need to log out on the Spotify UI, cannot do it from code.
In my case, the application saves the logged in user's email (I need that to show on the UI, anyway). When I want to log the user out programmatically, I just delete the saved email from the app and call
clearCookies()
when I start Spotify's Activity if the variable is empty.
A bit late, but you can use this AuthorizationClient.clearCookies(this) as
AuthenticationClient no longer exists
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
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.