1

Is there a way to get primary email address on Android 1.6 ? If yes, please suggest me.

Thank in advance.

Ferdinand
  • 1,175
  • 4
  • 22
  • 43
  • possible duplicate of [How can I get primary email address of a contact](http://stackoverflow.com/questions/2009943/how-can-i-get-primary-email-address-of-a-contact) – Ted Hopp May 10 '11 at 16:39
  • Yes. I've read that thread. I don't know how to set "selection" as defined String on below: Cursor cursor = context.getContentResolver().query(People.CONTENT_URI, new String[] {People._ID, People.PRIMARY_EMAIL_ID}, selection, null, null); – Ferdinand May 11 '11 at 03:54

1 Answers1

0

See sohilv's answer to this question.He says:
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

Community
  • 1
  • 1
hasanghaforian
  • 13,498
  • 9
  • 73
  • 157