原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://superfly81.blog.51cto.com/6302302/1317373

Java:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
     * 获取当前用户邮箱
     */
    public 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;
      }

还需要申请权限AndroidManifest.xml:

 

 

 

1
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

 

Ok了~ 测试通过的哟~

再放一个邮箱的正则:

1
2
3
4
5
6
7
8
9
10
/**
     * 邮箱判断正则表达式
     * @param eMAIL1
     * @return
     */
    public static boolean MatchEmail(String eMAIL1) {
         Pattern pattern = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
         Matcher mc = pattern.matcher(eMAIL1);
         return mc.matches();
     }

 

本文出自 “FlyHome” 博客,请务必保留此出处http://superfly81.blog.51cto.com/6302302/1317373

 

 

 

 

 

 

 

 

8.0之後別種寫法

arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()