我是 Google 的 Android 平台上的新开发人员 - 我的 HTC Desire 上周到货了。
现在我需要一种方法来登录我现有的应用程序(Java,目前在码头上运行)。 服务端Application使用spring security 3.0.2开发
就我而言,我想支持以下内容: 如果用户使用 googlemail/google-Account 设置了他的 Android 手机(大多数用户都这样做),我想使用此帐户凭据自动登录到我的服务器应用程序。
是否有任何 Android 框架支持该用例? 或者有其他选择吗?
我阅读:http code.google.com intl/de-DE/apis/accounts/docs/OpenID.html
此处描述了我们如何使用 Google AppEngine 上的应用登录:http://blog.notdot.net/2010/05/Authenticating-against-App-Engine-from-an-Android-app
最佳答案
我想你想要的是使用 AccountManager
要了解 Google 帐户的类型,请使用以下内容:
AuthenticatorDescription[] types = mAccountManager.getAuthenticatorTypes(); //
for (AuthenticatorDescription type : types) {
Log.d("account types", type.type);
}
然后做类似的事情
AccountManager mAccountManager = AccountManager.get(context);
Account[] mAccounts = AccountManager.get(context).getAccountsByType("com.google");
// Choose which account to use if there are multiple google accounts registered, save to Account mAccount
AccountManagerFuture<options> response = mAccountManager.getAuthToken(mAccount, type, options, activity, mCallback, mHandler); // define callback and handler yourself for where to return
当用户在你的 mHandler 中到达 mCallback 时,登录过程就完成了。如果用户尚未登录到他/她的 Google 帐户,则将使用通常的 google 登录对话框。
自己尝试一下,如果对您有帮助,请告诉我!
关于android - 需要登录的 Android 应用程序的 OpenID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3330761/