List of usage examples for android.accounts AccountManager getAuthToken
@Deprecated public AccountManagerFuture<Bundle> getAuthToken(final Account account, final String authTokenType, final boolean notifyAuthFailure, AccountManagerCallback<Bundle> callback, Handler handler)
From source file:Main.java
/** * This version is for running in the background. It may show the user an access request screen in the * notification area for the user to authorize the app * @param accountManager// w ww . java2s.co m * @param account * @param ota * @param activity */ public static void getAuthTokenFromAccountManager(AccountManager accountManager, Account account, AccountManagerCallback<Bundle> ota) { accountManager.getAuthToken(account, // Account retrieved using getAccountsByType() DOCS_SCOPE, // Authorization scope true, // Callback ota, // Callback called when a token is successfully acquired null); // Callback called if an error occurs }
From source file:Main.java
/** * This version puts a message in the notification area asking for authorization * * @param accountManager/*from w ww . j a va 2 s. com*/ * @param account * @param ota */ public static void GetAuthTokenFromAccountManager(AccountManager accountManager, Account account, AccountManagerCallback<Bundle> ota) { accountManager.getAuthToken(account, // Account retrieved using getAccountsByType() SCOPE, // Auth scope true, ota, // Callback called when a token is successfully acquired null); // Callback called if an error occurs }
From source file:sg.macbuntu.android.pushcontacts.DeviceRegistrar.java
private static String getAuthToken(Context context, Account account) { String authToken = null;/*from www . j a v a 2 s .co m*/ AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { // No auth token - will need to ask permission from user. Intent intent = new Intent(ActivityUI.AUTH_PERMISSION_ACTION); intent.putExtra("AccountManagerBundle", bundle); context.sendBroadcast(intent); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.martineve.mendroid.sync.MendeleySyncAdapter.java
private static void performSync(Context context, Application app, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) throws OperationCanceledException { Log.i(TAG, "Performing sync for account: " + account.toString()); mContentResolver = context.getContentResolver(); AccountManager am = AccountManager.get(app); AccountManagerCB AMC = new AccountManagerCB(app); Log.i(TAG, "Retrieving auth token."); am.getAuthToken(account, "com.martineve.mendroid.account", true, AMC, null); }
From source file:com.browsertophone.AppEngineClient.java
private String getAuthToken(Context context, Account account) { String authToken = null;//from w ww . j ava 2 s . com AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { // No auth token - will need to ask permission from user. Intent intent = new Intent(SetupActivity.AUTH_PERMISSION_ACTION); intent.putExtra("AccountManagerBundle", bundle); context.sendBroadcast(intent); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.lvlstudios.android.gtmessage.AppEngineClient.java
private String getAuthToken(Context context, Account account) throws PendingAuthException { String authToken = null;/* w w w.j a va 2 s . c o m*/ AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); if (authToken == null) { throw new PendingAuthException(bundle); } } catch (OperationCanceledException e) { Log.w(TAG, "AppEngineClient.getAuthToken " + e); } catch (AuthenticatorException e) { Log.w(TAG, "AppEngineClient.getAuthToken " + e); } catch (IOException e) { Log.w(TAG, "AppEngineClient.getAuthToken " + e); } return authToken; }
From source file:com.google.android.apps.chrometophone.AppEngineClient.java
private String getAuthToken(Context context, Account account) throws PendingAuthException { String authToken = null;// www . j av a 2 s . c o m AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); if (authToken == null) { throw new PendingAuthException(bundle); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.agiro.scanner.android.AppEngineClient.java
private String getAuthToken(Context context, Account account) { String authToken = null;//from w ww. java2s .c o m AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); Account[] accs = accountManager.getAccounts(); Log.v(TAG, "Account size = " + accs.length); Log.v(TAG, "Listing accounts"); for (Account acc : accs) { Log.v(TAG, "Account: " + acc); } authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { Log.e(TAG, "No authToken"); // No auth token - will need to ask permission from user. Intent intent = new Intent("com.google.ctp.AUTH_PERMISSION"); intent.putExtra("AccountManagerBundle", bundle); context.sendBroadcast(intent); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.notifry.android.remote.BackendClient.java
private String getAuthToken(Context context, Account account) throws PendingAuthException { String authToken = null;//from www . j av a 2 s . com AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, "ah", false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { // No auth token - will need to ask permission from user. Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { // User input required context.startActivity(intent); throw new PendingAuthException("Asking user for permission."); } } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public String getAuthToken(Context ctx, String inAuthority) throws OperationCanceledException, AuthenticatorException, IOException { final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority; AccountManager am = AccountManager.get(ctx); AccountManagerFuture<Bundle> future = am.getAuthToken( new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)), authority, true, null, null);/*w w w . j av a 2 s .c o m*/ String token = null; if (future.isDone()) { token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); } return token; }