问题描述
||
我想验证用户名和密码是否有效(例如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();
}
}