List of usage examples for android.accounts AccountManagerCallback AccountManagerCallback
AccountManagerCallback
From source file:com.example.ami1.CheckActivity.java
@Override public void onResume() { super.onResume(); // Get the account list, and pick the first one AccountManager.get(this).getAccountsByTypeAndFeatures(ACCOUNT_TYPE_GOOGLE, FEATURES_MAIL, new AccountManagerCallback<Account[]>() { @Override/*from ww w. ja v a2 s. com*/ public void run(AccountManagerFuture<Account[]> future) { Account[] accounts = null; try { accounts = future.getResult(); } catch (OperationCanceledException oce) { Log.e(TAG, "Got OperationCanceledException", oce); } catch (IOException ioe) { Log.e(TAG, "Got OperationCanceledException", ioe); } catch (AuthenticatorException ae) { Log.e(TAG, "Got OperationCanceledException", ae); } onAccountResults(accounts); } }, null /* handler */); }
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 w w. j ava 2 s. com 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: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//from w w w . ja v a 2s .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(); } }
From source file:com.github.riotopsys.shoppinglist.activity.ShoppingListPreview.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shopping_list_preview); AccountUtils accountUtils = new AccountUtils(); String account = accountUtils.getAccountName(this); if (account == null) { AccountManager am = AccountManager.get(this); am.getAuthTokenByFeatures(AppKeys.ACCOUNT_TYPE, AppKeys.OAUTH2_SCOPE, null, this, null, null, new AccountManagerCallback<Bundle>() { @Override// ww w . jav a2 s .c o m public void run(AccountManagerFuture<Bundle> future) { try { Bundle bundle = future.getResult(); Log.i(TAG, "Got Bundle:\n" + " act name: " + bundle.getString(AccountManager.KEY_ACCOUNT_NAME) + "\n act type: " + bundle.getString(AccountManager.KEY_ACCOUNT_TYPE) + "\n auth token: " + bundle.getString(AccountManager.KEY_AUTHTOKEN)); AccountUtils accountUtils = new AccountUtils(); accountUtils.setAccountName(getBaseContext(), bundle.getString(AccountManager.KEY_ACCOUNT_NAME)); accountUtils.setToken(getBaseContext(), bundle.getString(AccountManager.KEY_AUTHTOKEN)); } catch (Exception e) { Log.i(TAG, "getAuthTokenByFeatures() cancelled or failed:", e); Toast.makeText(getBaseContext(), R.string.no_account, Toast.LENGTH_LONG).show(); finish(); } } }, null); } mShoppingListCollection = new ShoppingListCollection(); mShoppingListCollectionAdapter = new ShoppingListCollectionAdapter(this, getSupportFragmentManager(), mShoppingListCollection); // mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mShoppingListCollectionAdapter); Intent startingIntent = getIntent(); if (startingIntent != null) { Uri data = startingIntent.getData(); if (data != null) { UUID guid = UUID.fromString(data.getLastPathSegment()); Intent i = new Intent(this, ServerInterfaceService.class); i.putExtra(AppKeys.SERVER_TASK_KEY, ServerTask.SUBSCRIBE); i.putExtra(AppKeys.GUID_KEY, guid); startService(i); } } IConfigurations config = new Configurations(); GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, config.getGCMSenderID()); } else { Log.v(TAG, "Already registered"); } }
From source file:be.evias.cloudLogin.cloudLoginRunPointActivity.java
/** * Add new account to the account manager for the cloudLogin * account type./*from w w w . j a v a 2 s . c om*/ * * @param accountType String * @param authTokenType String */ private void addNewAccount(String accountType, String authTokenType) { final AccountManagerFuture<Bundle> future = mAccountManager.addAccount(accountType, authTokenType, null, null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bnd = future.getResult(); showMessage(getBaseContext().getString(R.string.message_account_created), Toast.LENGTH_SHORT); Log.d("cloudLogin", "AddNewAccount Bundle is " + bnd); final Account account = new Account(bnd.getString(AccountManager.KEY_ACCOUNT_NAME), bnd.getString(AccountManager.KEY_ACCOUNT_TYPE)); SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean("cloudlogin_active_account", true); editor.putString("cloudlogin_active_account_name", account.name); editor.commit(); displayNavigationDrawer(bnd, account); } catch (Exception e) { e.printStackTrace(); showMessage(e.getMessage(), Toast.LENGTH_LONG); SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean("cloudlogin_active_account", false); editor.commit(); } } }, null); }
From source file:com.noswap.keyring.MainActivity.java
public void doGCMStuff() { GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { Log.v(TAG, "Registering"); GCMRegistrar.register(this, SENDER_ID); } else {//from www . j av a2 s . co m Log.v(TAG, "Already registered: " + regId); } AccountManager am = AccountManager.get(this); Account[] accounts = am.getAccountsByType("com.google"); for (Account account : accounts) { Log.v(TAG, "Account: " + account.name + " (" + account.type + ")"); } if (accounts.length > 0) { Account account = accounts[0]; Bundle options = new Bundle(); am.getAuthToken(account, "Keyring", options, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> result) { try { Bundle bundle = result.getResult(); String token = bundle.getString(AccountManager.KEY_AUTHTOKEN); Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { startActivityForResult(intent, 0); return; } Log.v(TAG, "onTokenAcquired: " + token); } catch (Exception e) { Log.v(TAG, "onTokenAcquired exception: " + e.toString()); } } }, new Handler() { }); } }
From source file:com.dhara.googlecalendartrial.MainActivity.java
private void getAccounts() { accountManager = AccountManager.get(this.getBaseContext()); Account[] accounts = accountManager.getAccountsByType("com.google"); account = accounts[0];//from w w w .j a v a2 s. c o m Log.e("tag", "acc : " + account.name + " "); accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, null, MainActivity.this, new AccountManagerCallback<Bundle>() { public void run(AccountManagerFuture<Bundle> future) { try { // If the user has authorized your application to use the tasks API // a token is available. String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); // Now you can use the Tasks API... useCalendarAPI(token, account.name); } catch (OperationCanceledException e) { // TODO: The user has denied you access to the API, you should handle that } catch (Exception e) { e.printStackTrace(); t.send(new HitBuilders.ExceptionBuilder().setDescription(Utilities.getMessage(e)) //.setDescription(new StandardExceptionParser(MainActivity.this, null).getDescription(Thread.currentThread().getName(), e)) .setFatal(false).build()); } } }, null); // Set screen name. // Where path is a String representing the screen name. t.setScreenName(getString(R.string.path)); // Send a screen view. t.send(new HitBuilders.AppViewBuilder().build()); }
From source file:com.todoroo.astrid.welcome.tutorial.WelcomeWalkthrough.java
private void initializeSimpleUI(final String email) { Button simpleLogin = (Button) findViewById(R.id.quick_login_google); simpleLogin.setText(getString(R.string.actfm_quick_login, email)); simpleLogin.setOnClickListener(new OnClickListener() { @Override/*from ww w . ja v a 2s . c o m*/ public void onClick(View v) { StatisticsService.reportEvent(StatisticsConstants.ACTFM_LOGIN_SIMPLE); final ProgressDialog pd = DialogUtilities.progressDialog(WelcomeWalkthrough.this, getString(R.string.gtasks_GLA_authenticating)); pd.show(); getAuthToken(email, pd); } private void getAuthToken(final String e, final ProgressDialog pd) { final GoogleAccountManager accountManager = new GoogleAccountManager(WelcomeWalkthrough.this); Account a = accountManager.getAccountByName(e); AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() { public void run(final AccountManagerFuture<Bundle> future) { new Thread() { @Override public void run() { try { Bundle bundle = future.getResult(30, TimeUnit.SECONDS); if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) { authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); if (!onSuccess) { accountManager.manager.invalidateAuthToken( ActFmGoogleAuthActivity.AUTH_TOKEN_TYPE, authToken); getAuthToken(e, pd); onSuccess = true; } else { onAuthTokenSuccess(e, authToken); dismissDialog = true; } } else { dismissDialog = true; } } catch (final Exception e) { Log.e("actfm-google-auth", "Login Error", e); //$NON-NLS-1$ //$NON-NLS-2$ runOnUiThread(new Runnable() { @Override public void run() { int error = e instanceof IOException ? R.string.gtasks_GLA_errorIOAuth : R.string.gtasks_GLA_errorAuth; Toast.makeText(WelcomeWalkthrough.this, error, Toast.LENGTH_LONG) .show(); onAuthError(); } }); } finally { if (dismissDialog) DialogUtilities.dismissDialog(WelcomeWalkthrough.this, pd); } } }.start(); } }; accountManager.manager.getAuthToken(a, ActFmGoogleAuthActivity.AUTH_TOKEN_TYPE, null, WelcomeWalkthrough.this, callback, null); } }); TextView rejectQuickLogin = (TextView) findViewById(R.id.quick_login_reject); rejectQuickLogin.setText(getString(R.string.actfm_quick_login_reject, email)); rejectQuickLogin.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { StatisticsService.reportEvent(StatisticsConstants.ACTFM_LOGIN_SIMPLE_REJECTED); switchToLoginPage(); } }); errors = (TextView) findViewById(R.id.error); }
From source file:uk.co.bubblebearapps.contactsintegration.MainActivity.java
/** * Add new account to the account manager * * @param accountType//from w w w .j a va 2 s .c om * @param authTokenType */ private void addNewAccount(String accountType, String authTokenType) { final AccountManagerFuture<Bundle> future = mAccountManager.addAccount(accountType, authTokenType, null, null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bnd = future.getResult(); showMessage("Account was created"); Log.d("udinic", "AddNewAccount Bundle is " + bnd); } catch (Exception e) { e.printStackTrace(); showMessage(e.getMessage()); } } }, null); }
From source file:com.gelakinetic.inboxwidget.InboxCheckerAppWidgetConfigure.java
/** * Start the process to get all Inbox accounts. Will call onAccountResults() when the accounts * are retrieved./*from w ww. j a v a 2 s.c o m*/ * * @throws SecurityException If permissions weren't granted, this is called */ private void getAccounts() throws SecurityException { /* Get all eligible accounts */ AccountManager.get(this).getAccountsByTypeAndFeatures(ACCOUNT_TYPE_GOOGLE, FEATURES_MAIL, new AccountManagerCallback<Account[]>() { @Override public void run(AccountManagerFuture<Account[]> future) { Account[] accounts = null; try { accounts = future.getResult(); } catch (OperationCanceledException | IOException | AuthenticatorException oce) { /* Eat it */ } onAccountResults(accounts); } }, null); }