微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有人有使用AccountManagerAndroid中的ConfirmCredentials API的经验

如何解决有没有人有使用AccountManagerAndroid中的ConfirmCredentials API的经验

|| 我想验证用户名和密码是否有效(例如Google帐户,Facebook帐户,Twitter帐户...)。我在AccountManager类中找到了和ConfirmCredentials API。我可以使用此API验证帐户密码吗?    我编写了这个checkCredentials API来检查用户密码是否有效,但这会导致ANR,而我无法获得密码结果是否有效?    您是否对此API有任何经验,或者如何验证Andoroid下的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,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();
    }
  }
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。