得到email的地址

加入权限是不可少的

<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
import android.accounts.Account; 
import android.accounts.AccountManager; 
import android.content.Context; 
 
/** 
 *  
 * 这个呢就是只得到主email也就是google
 */
 
public class UserEmailFetcher { 
 
 
static String getEmail(Context context) { 
   
AccountManager accountManager = AccountManager.get(context);  
   
Account account = getAccount(accountManager); 
 
   
if (account == null) { 
     
return null; 
   
} else { 
     
return account.name; 
   
} 
 
} 
 
 
private static Account getAccount(AccountManager accountManager) { 
   
Account[] accounts = accountManager.getAccountsByType("com.google"); 
   
Account account; 
   
if (accounts.length > 0) { 
      account
= accounts[0];       
   
} else { 
      account
= null; 
   
} 
   
return account; 
 
} 
}

2.

Account[] accounts = AccountManager.get(this).getAccounts(); 
for (Account account : accounts) { 
 
// TODO: Check possibleEmail against an email regex or treat 
 
// account.name as an email address only for certain account.type values. 
 
String possibleEmail = account.name; 
 
... 
} 

3.第三方

http://donpark.org/blog/2009/01/24/android-client-side-oauth

 in case anyone is interested: I have written an OAuth library for Java that works pretty well with Android. Check it out at http://code.google.com/p/oauth-signpost

你可能感兴趣的:(android,Google,Blog)