问题描述
要在 Android 2.0 之后的版本中检索帐户(信息),您可以使用 Android 2.0 中引入的 AccountManager.
For retrieving the accounts (information) in Android versions since 2.0 you can use the AccountManager that has been introduced in Android 2.0.
但现在我有一个问题,我想保持与至少 Android 1.6 的兼容性,有没有办法在 Android 1.6 中检索帐户信息?
But now I have the problem I want to maintain compatibility with atleast Android 1.6, is there any way to retrieve account information in Android 1.6?
推荐答案
- 从以下位置下载 framework.jar:http://github.com/android/platform_frameworks_opt_com.google.android/...并将其添加到您的构建路径中.这是某种接口谷歌设备功能.
调用方法:
- download the framework.jar from:http://github.com/android/platform_frameworks_opt_com.google.android/...and add it to you build path. this is some sort of an interface to theGoogle device functions.
call the method:
com.google.android.googlelogin.GoogleLoginServiceHelper.getAccount(Activity activity, int requestCode, boolean requireGoogle);
com.google.android.googlelogin.GoogleLoginServiceHelper.getAccount(Activity activity, int requestCode, boolean requireGoogle);
在哪里:Activity:是你的Activity,它在onActivityResult()requestCode:你的代码requireGoogle:应该是真的
where:Activity: is your Activity which get the result in theonActivityResult()requestCode: your coderequireGoogle: should be true
前.GoogleLoginServiceHelper.getAccount(mActivity, 123, true);
EX. GoogleLoginServiceHelper.getAccount(mActivity, 123, true);
3.覆盖 onActivityResult() 像:
3.override the onActivityResult() like:
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++;
}
}
}
原始帖子是 /a>
original post is here
这篇关于获取 Android 中的主要 gmail 帐户用户名 <2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!