分享

转载:Android 获取手机的account账户信息

 jnstyle 2016-07-05
通常使用Android手机的使用者都会把自己的Google账号给设定在手机上,这样一来才能使用Google提供的多种服务。像是Marke、Gmail或是Google Talk等等。也有一些软体开发者会用Google账号来当做注册的资讯使用,这样使用者就算换了其它支Android手机的话,只要Google账号不变就能继续享有原先的权利。Android SDK 2.0中开始提供AccountManager来让开发者能存取Account信息:

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
AccountManager accountManager =  AccountManager.get(context); 
Account[] accounts = accountManager.getAccounts(); 
for(Account account:accounts){
Log.w(TAG, "hongyan:account.name="+account.name);
Log.w(TAG, "hongyan:account.type="+account.type);}
Log.w(TAG, "hongyan:accounts.length="+accounts.length);
如果添加账户只有一个,比如:zhangyina0317@gmail.com
打印出来结果:
account.name=zhangyina0317@gmail.com
accoutn.type=com.android.exchange
account.length=1


添加权限:

 android:name = "android.permission.GET_ACCOUNTS"  />

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多