获取Android的&LT Gmail主帐户的用户名; 2.0帐户、用户名、LT、Android

2023-09-12 07:38:06 作者:指间淡淡の烟草香 ╮

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

已经推出了的AccountManager

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

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

调用方法:

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

原来的职位是这里

安卓 Android 手机如何登录Gmail邮箱

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?

解决方案

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);

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