Code example for AccountManager

Methods: addAccountExplicitly, setAuthToken, setUserData

0
 
            //Make account sync automatically 
            getContentResolver().setSyncAutomatically(account, "com.brookes.psntrophies.provider", true);
            // Creating the account on the device and setting the auth token we got 
            // (Not setting the auth token will cause another call to the server to authenticate the user) 
            mAccountManager.addAccountExplicitly(account, accountPassword, null);
            mAccountManager.setAuthToken(account, authtokenType, authtoken);
            mAccountManager.setUserData(account, "email", authtoken);
        } else { 
            mAccountManager.setPassword(account, accountPassword);
        } 
        setResult(RESULT_OK, intent);
        finish();
    } 
 
    @Override 
    public void onAccountAuthenticated(String username) {
        pDialog.cancel();
        if(username.isEmpty()){
            errorField.setText("Username/Password is incorrect");
        }