3
A
回答
1
你得把你的用戶界面,而是增加現有帳戶的最簡單的代碼將是這樣的:
AccountMager mgr = (AccountManager)getSystemService(ACCOUNT_SERVICE);
Account acc = new Account("[email protected]", "com.google"));
if(mgr.addAccountExplicitly(acc, "password", new Bundle())) {
//account added successfully
//do whatever is needed;
}
else {
//something did not work
}
您需要AUTHENTICATE_ACCOUNTS
許可。如果您通過null
代替密碼,則該帳戶將被添加而沒有密碼,並且在下一次重新同步時將提示用戶輸入密碼。
如果您需要更多的控制權的過程中,那麼您可以在AccountManager
類使用方法
public AccountManagerFuture<Bundle> addAccount (String accountType,
String authTokenType,
String[] requiredFeatures,
Bundle addAccountOptions,
Activity activity,
AccountManagerCallback<Bundle> callback,
Handler handler)
。查看AccountManager
class documentation瞭解更多詳情。
感謝您的回答。我收到以下異常: E/AndroidRuntime(1583):java.lang.SecurityException:調用方uid 10009與認證者的uid不同 – Ricmcm 2012-07-13 08:30:15
看看[這個問題](http://stackoverflow.com/questions/3774282/securityexception-caller-uid-xxxx-is-different-authenticator-uid) - 這可能與「com.google」字符串有關。最好的辦法是使用一個android類中的常量,但我不記得它在哪裏。 – 2012-07-13 08:38:36
我認爲「與認證者的uid不同」的例外是說您不能製作「com.google」帳戶,因爲您不是Google。換句話說,原來的問題是不可能的。如果我錯了,請糾正我的錯誤! – 2014-01-28 00:09:22