获取Android的&LT Gmail主帐户的用户名; 2.0 [英] Get main gmail account username in Android < 2.0

查看:175
本文介绍了获取Android的&LT Gmail主帐户的用户名; 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关检索帐户(信息),Android的版本,因为2.0,您可以使用已在Android 2.0的。

已经推出了的AccountManager

但现在我有我想要保持与ATLEAST Android 1.6的兼容性的问题,有没有什么办法可以检索帐户信息的Andr​​oid 1.6?

解决方案
  1. 从下载framework.jar: http://github.com/android/platform_frameworks_opt_com.google.android/ .. 。 并把它添加到您构建路径。这是某种一个接口的 谷歌设备功能。
  2. 调用方法:

    com.google.android.googlelogin.GoogleLoginServiceHelper.getAccount(活动活动,诠释请求code,布尔requireGoogle);

    在这里: 活动:为你的活动而得到的结果,在 onActivityResult() 请求code:你的code requireGoogle:应该是真实的

    EX。 GoogleLoginServiceHelper.getAccount(mActivity,123,真正的);

3.override的onActivityResult()这样的:

 保护无效onActivityResult(INT申请code,INT结果code,
    意图数据){
            super.onActivityResult(要求code,因此code,数据);
            如果(要求code == 123){
                的System.out.println(结果code);
                字符串键=户口;
                的System.out.println(键+:+
    Arrays.toString(da​​ta.getExtras()getStringArray(键)));
                。字符串帐户[] = data.getExtras()getStringArray(密钥);
                如果(帐户!= NULL){
                   INT I = 0;
                   对于(字符串交流:帐户){//每个账户是全
    电子邮件地址注册了该设备
                        的System.out.println(AC+ I +=+ AC);
                         我++;
                   }
                }
       }
 

原来的职位是<一个href="http://www.google.com/url?sa=D&q=http://groups.google.com/group/android-developers/browse_thread/thread/7a6bf77910ca31e0/7a7659d61a89fa41%3Flnk%3Dgst%26q%3Dhow%2Bcan%2BI%2Bget%2Bthe%2BGoogle%2Baccount%2Bor%2BGmail%2Baddress%2Bfrom%2Bthe%2Bphone%237a7659d61a89fa41&usg=AFQjCNHjHC0BihXAkabib4ScyoqHPc3w4Q"相对=nofollow>这里

For retrieving the accounts (information) in Android versions since 2.0 you can use the AccountManager that has been introduced in Android 2.0.

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?

解决方案

  1. 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.
  2. call the method:

    com.google.android.googlelogin.GoogleLoginServiceHelper.getAccount(Activity activity, int requestCode, boolean requireGoogle);

    where: Activity: is your Activity which get the result in the onActivityResult() requestCode: your code requireGoogle: should be true

    EX. GoogleLoginServiceHelper.getAccount(mActivity, 123, true);

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++; 
                   } 
                } 
       } 

original post is here

这篇关于获取Android的&LT Gmail主帐户的用户名; 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆