Example usage for android.accounts AccountManager KEY_INTENT

List of usage examples for android.accounts AccountManager KEY_INTENT

Introduction

In this page you can find the example usage for android.accounts AccountManager KEY_INTENT.

Prototype

String KEY_INTENT

To view the source code for android.accounts AccountManager KEY_INTENT.

Click Source Link

Document

Bundle key used for an Intent in results from methods that may require the caller to interact with the user.

Usage

From source file:pt.up.mobile.authenticator.Authenticator.java

@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType,
        String[] requiredFeatures, Bundle options) {
    Log.v(TAG, "addAccount()");
    final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}

From source file:org.ohmage.auth.Authenticator.java

@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType,
        String[] requiredFeatures, Bundle options) {
    // TODO: decide if we should allow more than one account, and if not, make it clear to the
    // user that they need to logout and login with a new account

    final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}

From source file:com.android.volley.toolbox.AndroidAuthenticator.java

@SuppressWarnings("deprecation")
@Override//from w w w . j  a v  a  2  s  .co  m
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, mAuthTokenType,
            mNotifyAuthFailure, null, null);
    Bundle result;
    try {
        result = future.getResult();
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
    String authToken = null;
    if (future.isDone() && !future.isCancelled()) {
        if (result.containsKey(AccountManager.KEY_INTENT)) {
            Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
            throw new AuthFailureError(intent);
        }
        authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
    }
    if (authToken == null) {
        throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
    }

    return authToken;
}

From source file:com.friedran.appengine.dashboard.client.AppEngineDashboardAuthenticator.java

public void executeAuthentication() {
    // Gets the auth token asynchronously, calling the callback with its result (uses the
    // deprecated API which is the only one supported from API level 5).
    AccountManager.get(mApplicationContext).getAuthToken(mAccount, AUTH_TOKEN_TYPE, false,
            new AccountManagerCallback<Bundle>() {
                public void run(AccountManagerFuture result) {
                    Bundle bundle;/*from w ww.j ava 2  s.  co  m*/
                    try {
                        LogUtils.i("AppEngineDashboardAuthenticator",
                                "GetAuthTokenCallback.onPostExecute started...");
                        bundle = (Bundle) result.getResult();
                        Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT);
                        if (intent != null) {
                            // User input required
                            LogUtils.i("AppEngineDashboardAuthenticator", "User input is required...");
                            mOnUserInputRequiredCallback.onUserInputRequired(intent);
                        } else {
                            LogUtils.i("AppEngineDashboardAuthenticator",
                                    "Authenticated, getting auth token...");
                            onGetAuthToken(bundle);
                        }
                    } catch (Exception e) {
                        // Can happen because of various like connectivity issues, google server errors, etc.
                        LogUtils.e("AppEngineDashboardAuthenticator",
                                "Exception caught from GetAuthTokenCallback", e);
                        mPostAuthenticateCallback.run(false);
                    }
                }
            }, null);
}

From source file:com.google.android.apps.chrometophone.ShareLinkActivity.java

private void sendLink() {
    new Thread(new Runnable() {
        public void run() {
            sendToast(getString(R.string.sending_link_toast));
            try {
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("url", mPendingLink));
                params.add(new BasicNameValuePair("deviceName", "Chrome"));
                SharedPreferences settings = Prefs.get(ShareLinkActivity.this);
                final String accountName = settings.getString("accountName", null);
                if (accountName == null) {
                    sendToast(getString(R.string.link_not_sent_auth_toast));
                    finish();/*w  w w .  j  a  v  a2s.c  om*/
                    return;
                }

                AppEngineClient client = new AppEngineClient(ShareLinkActivity.this, accountName);
                HttpResponse res = client.makeRequest(SEND_PATH, params);
                if (res.getStatusLine().getStatusCode() == 200) {
                    sendToast(getString(R.string.link_sent_toast));
                } else {
                    sendToast(getString(R.string.link_not_sent_toast));
                }
                finish();
            } catch (AppEngineClient.PendingAuthException pae) {
                Intent authIntent = (Intent) pae.getAccountManagerBundle().get(AccountManager.KEY_INTENT);
                if (authIntent != null && !mPendingAuth) {
                    mPendingAuth = true;
                    mHandler.sendMessage(Message.obtain(mHandler, START_ACTIVITY_MSG, 0, 0, authIntent));
                } else {
                    sendToast(getString(R.string.link_not_sent_auth_toast));
                    finish();
                }
            } catch (Exception e) {
                sendToast(getString(R.string.link_not_sent_toast));
                finish();
            }
        }
    }).start();
}

From source file:org.klnusbaum.udj.auth.Authenticator.java

@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,
        Bundle loginOptions) {/*  w ww. j a  v a 2s.c  o  m*/
    final AccountManager am = AccountManager.get(context);
    final String password = am.getPassword(account);
    if (password != null) {
        try {
            final ServerConnection.AuthResult authResult = ServerConnection.authenticate(account.name,
                    password);
            if (!TextUtils.isEmpty(authResult.ticketHash)) {
                am.setUserData(account, Constants.USER_ID_DATA, authResult.userId);
                return bundleUpAuthToken(account, authResult.ticketHash);
            }
        } catch (AuthenticationException e) {
            //TODO actually do something with this exception 
        } catch (IOException e) {
            //TODO actually do something with this exception 
        } catch (JSONException e) {
            //TODO actually do something with this exception 
        } catch (APIVersionException e) {
            final Intent intent = new Intent(context, NeedUpdateActivity.class);
            intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
            intent.putExtra(AccountManager.KEY_ERROR_CODE, Constants.AUTH_API_VERSION_ERROR);
            final Bundle bundle = new Bundle();
            bundle.putParcelable(AccountManager.KEY_INTENT, intent);
            return bundle;
        }
    }

    //Oh snap, they're username and password didn't work. O well, better have
    // them sort it out.
    final Intent intent = new Intent(context, AuthActivity.class);
    intent.putExtra(AuthActivity.PARAM_USERNAME, account.name);
    intent.putExtra(AuthActivity.PARAM_AUTHTOKEN_TYPE, authTokenType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}

From source file:edu.mit.mobile.android.locast.accounts.Authenticator.java

/**
 * {@inheritDoc}//from  w  ww .j  av a2s  .c o  m
 */
@Override
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) {
    if (options != null && options.containsKey(AccountManager.KEY_PASSWORD)) {
        final String password = options.getString(AccountManager.KEY_PASSWORD);
        final Bundle verified = onlineConfirmPassword(account, password);
        final Bundle result = new Bundle();
        result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, verified != null);
        return result;
    }
    // Launch AuthenticatorActivity to confirm credentials
    final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
    intent.putExtra(AuthenticatorActivity.EXTRA_USERNAME, account.name);
    intent.putExtra(AuthenticatorActivity.EXTRA_CONFIRMCREDENTIALS, true);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}

From source file:edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticator.java

/**
 * {@inheritDoc}/*from w  w w .  j a v  a  2  s  .c  o m*/
 */
@Override
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) {
    if (options != null && options.containsKey(AccountManager.KEY_PASSWORD)) {
        final String password = options.getString(AccountManager.KEY_PASSWORD);
        final Bundle verified = onlineConfirmPassword(account, password);
        final Bundle result = new Bundle();
        result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, verified != null);
        return result;
    }
    // Launch AuthenticatorActivity to confirm credentials
    final Intent intent = getAuthenticator(mContext);
    intent.putExtra(AbsLocastAuthenticatorActivity.EXTRA_USERNAME, account.name);
    intent.putExtra(AbsLocastAuthenticatorActivity.EXTRA_CONFIRMCREDENTIALS, true);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}

From source file:de.msal.shoutemo.connector.GetPostsService.java

@Override
public void onCreate() {
    super.onCreate();

    broadcaster = LocalBroadcastManager.getInstance(this);

    mAccountManager = AccountManager.get(this);
    Account[] acc = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);

    /* No account; push the user into adding one */
    if (acc.length == 0) {
        Log.v(TAG, "No suitable account found, directing user to add one.");
        mAccountManager.addAccount(AccountAuthenticator.ACCOUNT_TYPE, null, null, new Bundle(), null,
                new AccountManagerCallback<Bundle>() {
                    @Override//ww w. java  2 s.  c om
                    public void run(AccountManagerFuture<Bundle> result) {
                        Bundle bundle;
                        try {
                            bundle = result.getResult();
                        } catch (OperationCanceledException e) {
                            e.printStackTrace();
                            return;
                        } catch (AuthenticatorException e) {
                            e.printStackTrace();
                            return;
                        } catch (IOException e) {
                            e.printStackTrace();
                            return;
                        }

                        /* no accounts saved, yet; ask the user for credentials */
                        Intent launch = bundle.getParcelable(AccountManager.KEY_INTENT);
                        if (launch != null) {
                            launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(launch);
                            return;
                        }

                        mAccount = new Account(bundle.getString(AccountManager.KEY_ACCOUNT_NAME),
                                bundle.getString(AccountManager.KEY_ACCOUNT_TYPE));
                        Log.v(TAG, "Added account " + mAccount.name + "; now fetching new posts.");
                        startGetPostsTask();
                    }
                }, null);
    } else {
        mAccount = acc[0];
        startGetPostsTask();
    }
}