要在 Android 2.0 之后的版本中检索帐户(信息),您可以使用 Android 2.0 中引入的 AccountManager。
但现在我有一个问题,我想保持与至少 Android 1.6 的兼容性,有没有办法在 Android 1.6 中检索帐户信息?
最佳答案
- 从以下网址下载 framework.jar: http://github.com/android/platform_frameworks_opt_com.google.android/ ... 并将其添加到您的构建路径中。这是某种接口(interface) 谷歌设备功能。
调用方法:
com.google.android.googlelogin.GoogleLoginServiceHelper.getAccount(Activity activity, int requestCode, boolean requireGoogle);
哪里: Activity:是你的Activity,它在 onActivityResult() requestCode:你的代码 requireGoogle:应该是真的
例如。 GoogleLoginServiceHelper.getAccount(mActivity, 123, true);
3.重写 onActivityResult() 就像:
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 123){
System.out.println(resultCode);
String key = "accounts";
System.out.println(key + ":" +
Arrays.toString(data.getExtras().getStringArray(key)));
String accounts[] = data.getExtras().getStringArray(key);
if(accounts != null){
int i = 0;
for(String ac : accounts){ //each account is the full
email address registered with this device
System.out.println("ac " + i + "=" + ac);
i++;
}
}
}
原帖是here
关于android - 在 Android < 2.0 中获取主 gmail 帐户用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3360926/