Code example for AccountManager

Methods: addAccountExplicitlygetAccountsByType

		return null; 
	void internalAddAccount() { 
    	//TODO: this does DB-access, so it needs to actually happen in a background thread. 
		final Account account = new Account(mAccountName, mAccountType);
		Account[] acs = mAccountManager.getAccountsByType(mAccountType);
		if(acs.length == 0) {
			Log.v(TAG, "actually adding account for " + mAccountName + " with type " + mAccountType);
			SyncAdapter.setSyncMarker(mContext, 0);
			mAccountManager.addAccountExplicitly(account, "", null);
			ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
			ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
			//also force it to sync once 
			ContentResolver.requestSync(account, ContactsContract.AUTHORITY, new Bundle());
Stop searching for code, let great code find you!  Add Codota to your java IDE