Code example for AccountManager

Methods: getAccountsByTypegetAuthToken

1
	protected void onCreate(Bundle _savedInstanceState)
	{ 
		super.onCreate(_savedInstanceState);
 
		AccountManager accountManager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
		final Account[] accounts = accountManager.getAccountsByType(TWITTER_ACCOUNT_TYPE);
		if (accounts.length > 0)
		{ 
			Log.d(TAG, "nb account: " + accounts.length);
			final Account account = accounts[0];
 
			String token = null;
			String secret = null;
 
			AccountManagerFuture<Bundle> response = null;
			response = accountManager.getAuthToken(account, TWITTER_ACCOUNT_TOKEN, null, this, null, null);
			try 
			{ 
				Bundle b = response.getResult();
				token = b.getString(AccountManager.KEY_AUTHTOKEN);
			} 
			catch (OperationCanceledException e)
			{ 
				e.printStackTrace();
			} 
			catch (AuthenticatorException e)
			{ 
				e.printStackTrace();
			} 
			catch (IOException e)
			{ 
				e.printStackTrace();
			} 
 
			response = accountManager.getAuthToken(account, TWITTER_ACCOUNT_SECRET, null, this, null, null);
			try 
			{ 
				Bundle b = response.getResult();
				secret = b.getString(AccountManager.KEY_AUTHTOKEN);
			} 
Contextual code suggestions in your IDE  Get Codota for Java