Example usage for android.accounts AccountManager newChooseAccountIntent

List of usage examples for android.accounts AccountManager newChooseAccountIntent

Introduction

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

Prototype

@Deprecated
static public Intent newChooseAccountIntent(Account selectedAccount, ArrayList<Account> allowableAccounts,
        String[] allowableAccountTypes, boolean alwaysPromptForAccount, String descriptionOverrideText,
        String addAccountAuthTokenType, String[] addAccountRequiredFeatures, Bundle addAccountOptions) 

Source Link

Document

Deprecated in favor of #newChooseAccountIntent(Account,List,String[],String,String,String[],Bundle) .

Usage

From source file:com.pindroid.activity.ChooseTagShortcut.java

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

    setContentView(R.layout.browse_tags);
    getSupportActionBar().setTitle(R.string.shortcut_activity_title);

    Intent i = AccountManager.newChooseAccountIntent(null, null, new String[] { Constants.ACCOUNT_TYPE }, false,
            null, null, null, null);//www  .  j  a  v  a2  s  .co  m
    startActivityForResult(i, Constants.REQUEST_CODE_ACCOUNT_CHANGE);

    frag = (BrowseTagsFragment) getSupportFragmentManager().findFragmentById(R.id.listcontent);
    frag.setUsername(username);
}

From source file:com.pindroid.activity.SaveReadLaterBookmark.java

protected void requestAccount() {
    Intent i = AccountManager.newChooseAccountIntent(null, null, new String[] { Constants.ACCOUNT_TYPE }, false,
            null, null, null, null);//from   w w  w  . jav a  2 s  .c  o m
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(i, Constants.REQUEST_CODE_ACCOUNT_CHANGE);
}

From source file:io.v.android.apps.account_manager.AccountActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account);
    mBaseContext = V.init(this);

    Intent intent = getIntent();//from w w w. ja  v a 2  s .  com
    if (intent == null) {
        replyWithError("Intent not found.");
        return;
    }
    // See if the caller wants to use a specific Google account to create the Vanadium account.
    // If null or empty string is passed, the user will be prompted to choose the Google
    // account to use.
    mAccountName = intent.getStringExtra(GOOGLE_ACCOUNT);
    if (mAccountName != null && !mAccountName.isEmpty()) {
        getIdentity();
        return;
    }
    Intent chooseIntent = AccountManager.newChooseAccountIntent(null, null, new String[] { "com.google" },
            false, null, null, null, null);
    startActivityForResult(chooseIntent, REQUEST_CODE_PICK_ACCOUNTS);
}

From source file:org.jboss.aerogear.cordova.oauth2.OauthGoogleServicesIntentHelper.java

public boolean triggerIntent(final JSONObject data) throws JSONException {
    scopes = "oauth2:" + (data.has("scopes") ? data.getString("scopes") : PROFILE_SCOPE);

    final String[] accountTypes = (data.has("accountTypes")) ? data.getString("accountTypes").split("\\s")
            : new String[] { "com.google" };

    Runnable runnable = new Runnable() {
        public void run() {
            try {
                Intent intent = AccountManager.newChooseAccountIntent(null, null, accountTypes, false, null,
                        null, null, null);
                cordova.getActivity().startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "Activity not found: " + e.toString());
                callbackContext.error("Plugin cannot find activity: " + e.toString());
            } catch (Exception e) {
                Log.e(TAG, "Exception: " + e.toString());
                callbackContext.error("Plugin failed to get account: " + e.toString());
            }//from w w w.  j a  v a 2 s. com
        }

        ;
    };
    cordova.getActivity().runOnUiThread(runnable);
    return true;
}

From source file:net.sf.diningout.app.ui.InitActivity.java

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    if (savedInstanceState == null) {
        if (!Prefs.getBoolean(this, APP, ACCOUNT_INITIALISED)) {
            startActivityForResult(AccountManager.newChooseAccountIntent(null, null,
                    new String[] { GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null), 0);
        } else {/*from  w w w.ja v  a2 s  .c o  m*/
            setDefaultContentView();
        }
    }
}

From source file:io.v.android.impl.google.services.blessing.BlessingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBaseContext = V.init(this);
    setFinishOnTouchOutside(false);/*from ww w  .  j av  a  2s .  c  o  m*/
    if (savedInstanceState != null) {
        mGoogleAccount = savedInstanceState.getString(STATE_GOOGLE_ACCOUNT);
        mPublicKey = (ECPublicKey) savedInstanceState.getSerializable(STATE_PUBLIC_KEY);
        mPrefKey = savedInstanceState.getString(STATE_PREF_KEY);
        return;
    }

    Intent intent = getIntent();
    if (intent == null) {
        replyWithError("Intent not found.");
        return;
    }
    // Get the public key of the application invoking this activity.
    mPublicKey = (ECPublicKey) intent.getSerializableExtra(EXTRA_PUBLIC_KEY);
    if (mPublicKey == null) {
        replyWithError("Empty blesee public key.");
        return;
    }
    // Get the SharedPreferences key where the blessings are to be stored.  If empty, blessings
    // aren't stored in preferences.
    if (intent.hasExtra(EXTRA_PREF_KEY)) {
        mPrefKey = intent.getStringExtra(EXTRA_PREF_KEY);
    }
    // Get the google email address (if any).
    mGoogleAccount = intent.getStringExtra(EXTRA_GOOGLE_ACCOUNT);
    if (mGoogleAccount == null || mGoogleAccount.isEmpty()) {
        // Prompt the user to choose the google account to use (if more than one).
        Intent accountIntent = AccountManager.newChooseAccountIntent(null, null, new String[] { "com.google" },
                false, null, null, null, null);
        startActivityForResult(accountIntent, REQUEST_CODE_PICK_ACCOUNT);
        return;
    }
    getBlessing();
}

From source file:io.v.android.apps.syncslides.SignInActivity.java

private void pickAccount() {
    Intent chooseIntent = AccountManager.newChooseAccountIntent(null, null, new String[] { "com.google" },
            false, null, null, null, null);
    startActivityForResult(chooseIntent, REQUEST_CODE_PICK_ACCOUNT);
}

From source file:org.geometerplus.android.fbreader.network.ActivityNetworkContext.java

@Override
protected boolean authenticateToken(URI uri, Map<String, String> params) {
    System.err.println("+++ TOKEN AUTH +++");
    try {//from   w w w .  j  av a2  s  .c  o m
        final String authUrl = url(uri, params, "auth-url-token");
        final String clientId = params.get("client-id");
        if (authUrl == null || clientId == null) {
            return false;
        }

        final Intent intent = AccountManager.newChooseAccountIntent(null, null, new String[] { "com.google" },
                false, null, null, null, null);
        startActivityAndWait(intent, NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER);
        if (myAccount == null) {
            return false;
        }
        final String authToken = GoogleAuthUtil.getToken(myActivity, myAccount,
                String.format("audience:server:client_id:%s", clientId));
        System.err.println("AUTH TOKEN = " + authToken);
        final String result = runTokenAuthorization(authUrl, authToken, null);
        System.err.println("AUTHENTICATION RESULT 1 = " + result);
        if ("SUCCESS".equals(result)) {
            return true;
        }
        return registerAccessToken(clientId, authUrl, authToken);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        System.err.println("--- TOKEN AUTH ---");
    }
}

From source file:org.geometerplus.android.fbreader.network.BearerAuthenticator.java

private boolean authenticateToken(URI uri, Map<String, String> params) {
    System.err.println("+++ TOKEN AUTH +++");
    try {/*from  www  .j  a  v a  2s.  c  om*/
        final String authUrl = url(uri, params, "auth-url-token");
        final String clientId = params.get("client-id");
        if (authUrl == null || clientId == null) {
            return false;
        }

        final Intent intent = AccountManager.newChooseAccountIntent(null, null, new String[] { "com.google" },
                false, null, null, null, null);
        startActivityAndWait(intent, NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER);
        if (myAccount == null) {
            return false;
        }
        final String authToken = GoogleAuthUtil.getToken(myActivity, myAccount,
                String.format("audience:server:client_id:%s", clientId));
        System.err.println("AUTH TOKEN = " + authToken);
        final String result = runTokenAuthorization(authUrl, authToken, null);
        System.err.println("AUTHENTICATION RESULT 1 = " + result);
        if ("SUCCESS".equals(result)) {
            return true;
        }
        return registerAccessToken(clientId, authUrl, authToken);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        System.err.println("--- TOKEN AUTH ---");
    }
}

From source file:com.beem.project.beem.ui.wizard.AccountConfigureFragment.java

@TargetApi(14)
@Override/*from   w w w .j  a v a2  s.c o m*/
public void onClick(View v) {
    if (v == mNextButton) {
        if (useSystemAccount) {
            onDeviceAccountSelected(settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, ""),
                    settings.getString(BeemApplication.ACCOUNT_SYSTEM_TYPE_KEY, ""));
        } else {
            String jid = mAccountJID.getText().toString();
            jid = StringUtils.parseBareAddress(jid);
            String password = mAccountPassword.getText().toString();
            task = new ConnectionTestTask();
            if (settings.getBoolean(BeemApplication.ACCOUNT_SPECIFIC_SERVER_KEY, false)) {
                String server = settings.getString(BeemApplication.ACCOUNT_SPECIFIC_SERVER_HOST_KEY, "");
                String port = settings.getString(BeemApplication.ACCOUNT_SPECIFIC_SERVER_PORT_KEY, "5222");
                task.execute(jid, password, server, port);
            } else
                task.execute(jid, password);
        }
    } else if (v == mManualConfigButton) {
        onManualConfigurationSelected();
    } else if (v == mSelectAccountButton) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            Intent i = AccountManager.newChooseAccountIntent(null, null, new String[] { GOOGLE_ACCOUNT_TYPE },
                    true, null, null, null, null);
            startActivityForResult(i, SELECT_ACCOUNT_CODE);
        }
    }
}