Get main gmail account username in Android < 2.0
Asked Answered
A

1

8

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?

Atalayah answered 29/7, 2010 at 9:12 Comment(0)
V
8
  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

Vadavaden answered 1/8, 2010 at 18:6 Comment(5)
also add the permission to manifest file: <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH"></ uses-permission>Vadavaden
I don't see a GoogleLoginServiceHelper in this jar. There is a GoogleLoginServiceBlockingHelper however, but which doesn't have the getAccount methodGaskin
You have to download a previous revision, search for one that contains the GoogleLoginServiceHelper, I found it and it works :DAtalayah
Addendum to the above, and to future finders: the last framework.jar with GoogleLoginServiceHelper is here: github.com/android/platform_frameworks_opt_com.google.android/… Committed September 02, 2009Marti
I am getting accounts as null in onActivityResult, I am trying with android2.2, any one have idea about this?Unconquerable

© 2022 - 2024 — McMap. All rights reserved.