Loading...

android-developers@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

[android-developers] Tut (SDK 1.5) Get google account of user Sujay Krishna Suresh Fri Jun 05 00:01:27 2009

hi guys i finally got a simple method to get the google accounts in SDK
1.5...
i'm attaching the code for everyone who needs this piece of code...
This piece of code prints all methods in the class & invokes the static
method getAccount...
try {
  for (Method ele :
Class.forName("com.google.android.googlelogin.GoogleLoginServiceHelper").getMethods())
{
  System.out.println(ele.toString());
  try {
  if(ele.getName().equals("getAccount"))
  ele.invoke(null, this, 123, true);
  } catch (IllegalArgumentException e) {
  e.printStackTrace();
  } catch (IllegalAccessException e) {
  e.printStackTrace();
  } catch (InvocationTargetException e) {
  e.printStackTrace();
  }
  }
  } catch (ClassNotFoundException e) {
  e.printStackTrace();
  }

  } catch (ClassNotFoundException e) {
  e.printStackTrace();
  }

& jus place the foll code in ur onactivityresult
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[0] != null)
  usernameText.setText("You are : " + accounts[0].replace("@gmail.com",
""));
 }
in the logcat/ddms o/p u'll be able to see that there are other useful
methods...
public static void
com.google.android.googlelogin.GoogleLoginServiceHelper.getCredentials(android.app.Activity,int,android.os.Bundle,java.lang.String,java.lang.String,boolean)
public static void
com.google.android.googlelogin.GoogleLoginServiceHelper.getCredentials(android.app.Activity,int,android.os.Bundle,boolean,java.lang.String,boolean)
public static void
com.google.android.googlelogin.GoogleLoginServiceHelper.invalidateAuthToken(android.app.Activity,int,java.lang.String)


-- 
Regards,
Sujay
Mark Twain <http://www.brainyquote.com/quotes/authors/m/mark_twain.html>  -
"There is no sadder sight than a young pessimist."

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---