Get main gmail account username in Android lt; 2.0(获取 Android 中的主要 gmail 帐户用户名 lt;2.0)
问题描述
要在 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 the Google 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 the onActivityResult() requestCode: your code requireGoogle: 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取 Android 中的主要 gmail 帐户用户名 <2.0
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01