当前位置: 首页>>代码示例>>Java>>正文


Java AccountManager.getAccountsByType方法代码示例

本文整理汇总了Java中android.accounts.AccountManager.getAccountsByType方法的典型用法代码示例。如果您正苦于以下问题:Java AccountManager.getAccountsByType方法的具体用法?Java AccountManager.getAccountsByType怎么用?Java AccountManager.getAccountsByType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.accounts.AccountManager的用法示例。


在下文中一共展示了AccountManager.getAccountsByType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initializeSyncAccount

import android.accounts.AccountManager; //导入方法依赖的package包/类
public void initializeSyncAccount(Context context, ContentResolver contentResolver) {
	initializeContactManager(context, contentResolver);
	AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

	Account[] accounts = accountManager.getAccountsByType(context.getPackageName());

	if (accounts != null && accounts.length == 0) {
		Account newAccount = new Account(context.getString(R.string.sync_account_name), context.getPackageName());
		try {
			accountManager.addAccountExplicitly(newAccount, null, null);
		} catch (Exception e) {
			Log.e(e);
		}
	}
	initializeContactManager(context, contentResolver);
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:17,代码来源:ContactsManager.java

示例2: getUsername

import android.accounts.AccountManager; //导入方法依赖的package包/类
public static String getUsername(Context c) {
    AccountManager manager = AccountManager.get(c);
    Account[] accounts = manager.getAccountsByType("com.google");
    List<String> possibleEmails = new LinkedList<String>();

    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.
        possibleEmails.add(account.name);
    }

    if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) {
        String email = possibleEmails.get(0);
        String[] parts = email.split("@");

        if (parts.length > 1)
            return parts[0];
    }
    return null;
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:21,代码来源:Util.java

示例3: current

import android.accounts.AccountManager; //导入方法依赖的package包/类
public static OUser current(Context context) {
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    Account[] accounts = accountManager.getAccountsByType(context.getString(R.string.auth_type));
    if (accounts.length > 0) {
        OUser user = new OUser();
        user.fillFromAccount(accountManager, accounts[0]);
        user.setAccount(accounts[0]);
        return user;
    }
    return null;
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:12,代码来源:OUser.java

示例4: setSyncActivated

import android.accounts.AccountManager; //导入方法依赖的package包/类
public void setSyncActivated(boolean enabled) {
	
       ContentResolver.setMasterSyncAutomatically(enabled);
       
       if (enabled) {
       	SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
       	AccountManager accmgr = AccountManager.get(mContext);
       	for (SyncAdapterType type : types) {
       		
       		Account[] accounts = accmgr.getAccountsByType(type.accountType);
       		for (Account account : accounts) {
       			
       			if (Constants.DEBUG) {
       				Log.d(TAG, "synching account, name:" + account.name  + ", type: " + account.type);
       			}
       			
       			enabled = ContentResolver.getSyncAutomatically(account, type.authority);
       			if (enabled) {
       				// trigger update for next account
       				ContentResolver.requestSync(account, type.authority, new Bundle());
       			}
       		}
       	}
       }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:26,代码来源:SyncControl20.java

示例5: deleteAllAppAccounts

import android.accounts.AccountManager; //导入方法依赖的package包/类
public void deleteAllAppAccounts() {
    try {
        AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
        Account[] accounts = am.getAccountsByType("org.telegram.messenger");
        for (int a = 0; a < accounts.length; a++) {
            am.removeAccount(accounts[a], null, null);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:12,代码来源:ContactsController.java

示例6: populateAccountTextView

import android.accounts.AccountManager; //导入方法依赖的package包/类
private void populateAccountTextView() {
    AccountManager am = AccountManager.get(this);
    Account[] accounts = am.getAccountsByType(ACCOUNT_TYPE);
    String accountString = "Accounts of type " + ACCOUNT_TYPE + " are : \n";
    if (accounts.length != 0) {
        for (Account account : accounts) {
            accountString += "Account:" +  account.name + "\n";
        }
    } else {
        accountString = "No Accounts of type " + ACCOUNT_TYPE +
                " found. Please add accounts before exporting.";
        mAccountTextView.setTextColor(Color.RED);
    }
    mAccountTextView.setText(accountString);
}
 
开发者ID:googlesamples,项目名称:account-transfer-api,代码行数:16,代码来源:MainActivity.java

示例7: sync

import android.accounts.AccountManager; //导入方法依赖的package包/类
public void sync(Bundle data) {
    AccountManager manager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    Account[] accounts = manager.getAccountsByType(context.getString(R.string.auth_type));
    if (accounts.length > 0) {
        Bundle settings = new Bundle();
        settings.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        settings.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
        settings.putString(SyncAdapter.KEY_SYNC_MODEL, model.getModelName());
        if (data != null)
            settings.putAll(data);
        ContentResolver.requestSync(accounts[0], model.getAuthority(), settings);
    }
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:14,代码来源:OSyncUtils.java

示例8: getOrCreateAccount

import android.accounts.AccountManager; //导入方法依赖的package包/类
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
  AccountManager accountManager = AccountManager.get(context);
  Account[]      accounts       = accountManager.getAccountsByType("im.cable.cableim");

  Optional<AccountHolder> account;

  if (accounts.length == 0) account = createAccount(context);
  else                      account = Optional.of(new AccountHolder(accounts[0], false));

  if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
    ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
  }

  return account;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:16,代码来源:DirectoryHelper.java

示例9: restoreUIFromPref

import android.accounts.AccountManager; //导入方法依赖的package包/类
protected void restoreUIFromPref() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());		
lastSyncLocalTimestamp=MyPreferences.getFlowzrLastSync(getApplicationContext());
		preferences.getLong(FlowzrSyncOptions.PROPERTY_LAST_SYNC_TIMESTAMP,0);
      AccountManager accountManager = AccountManager.get(getApplicationContext());
Account[] accounts = accountManager.getAccountsByType("com.google");
      for (Account account : accounts) {
          if (preferences.getString(FlowzrSyncOptions.PROPERTY_USE_CREDENTIAL, "").equals(account.name)) {
              useCredential = account;
          }
      }
      TextView tv = (TextView) findViewById(R.id.sync_was);
      tv.setText(getString(R.string.flowzr_sync_was) + " " + new Date(lastSyncLocalTimestamp).toLocaleString());

  }
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:16,代码来源:FlowzrSyncActivity.java

示例10: work

import android.accounts.AccountManager; //导入方法依赖的package包/类
protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException {    	

    	AccountManager accountManager = AccountManager.get(context);
		android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google");
		
	    String accountName=MyPreferences.getFlowzrAccount(context);
        if (accountName == null) {
			NotificationManager nm = (NotificationManager) context
					.getSystemService(Context.NOTIFICATION_SERVICE);

			Intent notificationIntent = new Intent(context,
					FlowzrSyncActivity.class);
			PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
					notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

			Builder mNotifyBuilder = new NotificationCompat.Builder(context);
			mNotifyBuilder
					.setContentIntent(contentIntent)
					.setSmallIcon(R.drawable.icon)
					.setWhen(System.currentTimeMillis())
					.setAutoCancel(true)
					.setContentTitle(context.getString(R.string.flowzr_sync))
					.setContentText(
							context.getString(R.string.flowzr_choose_account));
			nm.notify(0, mNotifyBuilder.build());		
			Log.i("Financisto","account name is null");
            throw new ImportExportException(R.string.flowzr_choose_account);
        }
		Account useCredential = null;
		for (int i = 0; i < accounts.length; i++) {
	    	 if (accountName.equals(((android.accounts.Account) accounts[i]).name)) {
	    		 useCredential=accounts[i];
	    	 }
	     }	    	
		accountManager.getAuthToken(useCredential, "ah", false, new GetAuthTokenCallback(), null);    	
    	return null;
    }
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:38,代码来源:FlowzrSyncTask.java

示例11: getMailByAccountManager

import android.accounts.AccountManager; //导入方法依赖的package包/类
public static String getMailByAccountManager(Context context) {
    AccountManager accManager = AccountManager.get(context);
    Pattern gmailPattern = Patterns.EMAIL_ADDRESS;
    Account acc[] = accManager.getAccountsByType("com.google");
    for (Account account : acc) {
        if (gmailPattern.matcher(account.name).matches()) {
            return account.name;
        }
    }
    WebtrekkLogging.log("could not get valid Account Email, check Permissions. Account:"+ Arrays.toString(accManager.getAccounts()));
    return "";
}
 
开发者ID:Webtrekk,项目名称:webtrekk-android-sdk,代码行数:13,代码来源:HelperFunctions.java

示例12: createSyncAccount

import android.accounts.AccountManager; //导入方法依赖的package包/类
private Account createSyncAccount() {
    AccountManager am = AccountManager.get(this);
    Account[] accounts;

    try {
        accounts = am.getAccountsByType("de.slg.leoapp");
    } catch (SecurityException e) {
        accounts = new Account[0];
    }
    if (accounts.length > 0) {
        return accounts[0];
    }
    Account newAccount = new Account("default_account", "de.slg.leoapp");
    if (am.addAccountExplicitly(newAccount, "pass1", null)) {
        ContentResolver.setIsSyncable(newAccount, "de.slg.leoapp", 1);
        ContentResolver.setSyncAutomatically(newAccount, "de.slg.leoapp", true);
    } else {
        newAccount = null;
    }

    return newAccount;
}
 
开发者ID:LCA311,项目名称:leoapp-sources,代码行数:23,代码来源:Start.java

示例13: signInOrCreateAnAccount

import android.accounts.AccountManager; //导入方法依赖的package包/类
private void signInOrCreateAnAccount() {
    //Get list of accounts on device.
    AccountManager am = AccountManager.get(BaseActivity.this);
    Account[] accountArray = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    if (accountArray.length == 0) {
        //Send the user to the "Add Account" page.
        Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
        intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES,
                new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE});
        startActivity(intent);
    } else {
        //Try to log the user in with the first account on the device.
        startLoginProcess();
        mDrawerLayout.closeDrawer(GravityCompat.START);
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:17,代码来源:BaseActivity.java

示例14: getAccount

import android.accounts.AccountManager; //导入方法依赖的package包/类
private static Account getAccount(Context context) {
    AccountManager accountManager = AccountManager.get(context);
    Account[] accounts = accountManager.getAccountsByType(SyncUtils.ACCOUNT_TYPE);
    Account account;
    if (accounts.length > 0) {
        account = accounts[0];
    } else {
        account = null;
    }

    return account;
}
 
开发者ID:jaydeepw,项目名称:simplest-sync-adapter,代码行数:13,代码来源:SyncUtils.java

示例15: getOrCreateAccount

import android.accounts.AccountManager; //导入方法依赖的package包/类
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
  AccountManager accountManager = AccountManager.get(context);
  Account[]      accounts       = accountManager.getAccountsByType("id.kita.pesan.secure");

  Optional<AccountHolder> account;

  if (accounts.length == 0) account = createAccount(context);
  else                      account = Optional.of(new AccountHolder(accounts[0], false));

  if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
    ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
  }

  return account;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:16,代码来源:DirectoryHelper.java


注:本文中的android.accounts.AccountManager.getAccountsByType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。