2011-06-12 72 views
2

我想驗證用戶名和密碼是否有效(例如Google帳戶,Facebook帳戶,Twitter帳戶等)。我在AccountManager類中找到並確認了confirmCredentials API。我可以使用此API來驗證帳戶的密碼嗎?
我寫這個checkCredentials用於檢查用戶密碼有效與否的API,但會導致ANR和我無法得到密碼的結果是否有效?
您是否有任何關於此API的經驗或如何驗證Andoroid下的ID和密碼?
任何信息或線索將不勝感激。非常感謝你。有沒有人有經驗在AccountManager中使用confirmCredentials API(Android)

回答

1

我在我的應用程序中使用了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(); 
    } 
    } 
相關問題