我在我的應用程序中使用了confirmCredentials。我已經把一些示例代碼下面的情況下,以幫助...
public class MyActivity implements AccountManagerCallback<Bundle>
<snip>
// Get the user to confirm their credentials
Account account = new Account("username", "com.mydomain.myapp");
// The result of this call is handled in the
// run(AccountManagerFuture<Bundle> response) method below
AccountManager.get(this).confirmCredentials(account,
null,
this,
this,
null);
<snip>
/**
* Handle callbacks from the {@link AccountManager} methods
*/
@Override
public void run(AccountManagerFuture<Bundle> response)
{
try
{
// This call blocks while waiting for result from confirmCredentials
Bundle result = response.getResult();
// Handle the result
}
catch (OperationCanceledException e)
{
// User cancelled login
e.printStackTrace();
}
catch (AuthenticatorException e)
{
// Failed to login
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
// Always exit
finish();
}
}