本測試使用Android Studio 進行開發,請注意確定已加入google Play Service 的 Module 進入專案中。
於build.gradle 內新增以下設定 :
dependencies {
compile 'com.google.android.gms:play-services-auth:8.4.0'
}
於 AndroidManifest.xml 加入以下權限 :
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Java Code :
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.i("--Get Account Example--", account.name);
Log.i("--Get Account Example--", account.type);
}
文章標籤
全站熱搜