是否有人有在AccountManager(Android)中使用confirmCredentials API的经验

是否有人有在AccountManager(Android)中使用confirmCredentials API的经验,android,accountmanager,Android,Accountmanager,我想验证用户ID和密码是否有效(如Google帐户、Facebook帐户、Twitter帐户…)。我在AccountManager类中找到了和confirmCredentialsAPI。我可以使用此API验证帐户的密码吗? 我编写了这个检查凭证API来检查用户密码是否有效,但它会导致ANR,我无法得到密码是否有效的结果? 您是否有关于此API的经验,或者如何在ANDROID下验证id和密码 任何信息或线索将不胜感激。非常感谢。我在我的应用程序中使用了confirmCredentials。我在下面

我想验证用户ID和密码是否有效(如Google帐户、Facebook帐户、Twitter帐户…)。我在AccountManager类中找到了和confirmCredentialsAPI。我可以使用此API验证帐户的密码吗?
我编写了这个检查凭证API来检查用户密码是否有效,但它会导致ANR,我无法得到密码是否有效的结果?
您是否有关于此API的经验,或者如何在ANDROID下验证id和密码

任何信息或线索将不胜感激。非常感谢。

我在我的应用程序中使用了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();
    }
  }
公共类MyActivity实现AccountManagerCallback
//让用户确认他们的凭据
账户=新账户(“用户名”,“com.mydomain.myapp”);
//此调用的结果将在中处理
//运行下面的(AccountManagerFuture响应)方法
AccountManager.get(this).confirmCredentials(account,
无效的
这
这
无效);
/**
*处理来自{@link AccountManager}方法的回调
*/
@凌驾
公共作废运行(AccountManagerFuture响应)
{
尝试
{
//此调用在等待confirmCredentials的结果时阻塞
Bundle result=response.getResult();
//处理结果
}
捕捉(操作取消异常e)
{
//用户已取消登录
e、 printStackTrace();
}
捕获(认证异常e)
{
//登录失败
e、 printStackTrace();
}
捕获(IOE异常)
{
e、 printStackTrace();
}
最后
{
//总是退出
完成();
}
}