I would like to retrieve passwords of all accounts (Facebook, Dropbox, Gmail, etc) associated in my Android phone... I have tried the coding below, but not able to get the passwords...
AccountManager am = AccountManager.get(this);
Account [] acc = am.getAccounts();
if (acc.length > 0){
for (int i=0; i<acc.length; i++){
String password = am.getPassword(acc[i]);
listedAcc += acc[i] + " Password:" + password.toString() + "\n\n";
}
accounts.setText(listedAcc.toString());
You can not do this
Only application which uses the same UID as the Authenticator for the facebook/gmail/../other accounts can call this method. Other applications will always get an error message.
The documentation of getPassword()
says:
This method requires the caller to hold the permission AUTHENTICATE_ACCOUNTS and to have the same UID as the account's authenticator.
I think the last part of the sentence is important in your case. You're trying to get the password for an account for which you haven't written the Authenticator. The Authenticator defines how to authenticate to a certain service. Only the authenticator or an application which uses the same UID are allowed to call the getPassword() method. By this restriction it is assured that no one can steal the user's account credentials.