List of usage examples for android.accounts OperationCanceledException printStackTrace
public void printStackTrace()
From source file:com.deliciousdroid.client.DeliciousApi.java
/** * Performs an api call to Delicious's http based api methods. * /*from w w w .j a va 2 s .c o m*/ * @param url URL of the api method to call. * @param params Extra parameters included in the api call, as specified by different methods. * @param account The account being synced. * @param context The current application context. * @return A String containing the response from the server. * @throws IOException If a server error was encountered. * @throws AuthenticationException If an authentication error was encountered. */ private static InputStream DeliciousApiCall(String url, TreeMap<String, String> params, Account account, Context context) throws IOException, AuthenticationException { final AccountManager am = AccountManager.get(context); if (account == null) throw new AuthenticationException(); final String username = account.name; String authtoken = null; try { authtoken = am.blockingGetAuthToken(account, Constants.AUTHTOKEN_TYPE, false); } catch (OperationCanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AuthenticatorException e) { // TODO Auto-generated catch block e.printStackTrace(); } Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME); builder.authority(DELICIOUS_AUTHORITY); builder.appendEncodedPath(url); for (String key : params.keySet()) { builder.appendQueryParameter(key, params.get(key)); } String apiCallUrl = builder.build().toString(); Log.d("apiCallUrl", apiCallUrl); final HttpGet post = new HttpGet(apiCallUrl); post.setHeader("User-Agent", "DeliciousDroid"); post.setHeader("Accept-Encoding", "gzip"); DefaultHttpClient client = (DefaultHttpClient) HttpClientFactory.getThreadSafeClient(); CredentialsProvider provider = client.getCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(username, authtoken); provider.setCredentials(SCOPE, credentials); client.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); final HttpResponse resp = client.execute(post); final int statusCode = resp.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { final HttpEntity entity = resp.getEntity(); InputStream instream = entity.getContent(); final Header encoding = entity.getContentEncoding(); if (encoding != null && encoding.getValue().equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); } return instream; } else if (statusCode == HttpStatus.SC_UNAUTHORIZED) { throw new AuthenticationException(); } else { throw new IOException(); } }
From source file:net.translatewiki.app.TranslateWikiApp.java
public Boolean revalidateAuthToken() { AccountManager accountManager = AccountManager.get(this); Account curAccount = getCurrentAccount(); if (curAccount == null) { return false; // This should never happen }// www. ja v a 2 s .c o m accountManager.invalidateAuthToken(getString(R.string.account_type_identifier), api.getAuthCookie()); try { String authCookie = accountManager.blockingGetAuthToken(curAccount, "", false); api.setAuthCookie(authCookie); return true; } catch (OperationCanceledException e) { e.printStackTrace(); return false; } catch (AuthenticatorException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:com.arthackday.killerapp.util.Util.java
public String getGoogleAuth(String type) { AccountManager mgr = AccountManager.get(activity); Account[] accts = mgr.getAccountsByType("com.google"); if (accts.length == 0) { return null; }/* w ww . j a v a 2 s. c o m*/ try { Account acct = accts[0]; Log.d(LOG_TAG, "acct name=" + acct.name); AccountManagerFuture<Bundle> accountManagerFuture = mgr.getAuthToken(acct, type, null, activity, null, null); Bundle authTokenBundle = accountManagerFuture.getResult(); if (authTokenBundle.containsKey(AccountManager.KEY_INTENT)) { Intent authRequestIntent = (Intent) authTokenBundle.get(AccountManager.KEY_INTENT); activity.startActivity(authRequestIntent); } return authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString(); } catch (OperationCanceledException e) { e.printStackTrace(); } catch (AuthenticatorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.clarionmedia.jockey.authentication.impl.appengine.AppEngineAuthenticator.java
@Override public Cookie authenticate() { try {//from w w w . j a v a2 s. c om String authToken = mAccountManager.blockingGetAuthToken(mAccount, TOKEN_TYPE, false); Cookie cookie = exchangeTokenForCookie(authToken); if (cookie != null) { persistAuthCookie(cookie); } return cookie; } catch (OperationCanceledException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (AuthenticatorException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return null; }
From source file:de.msal.shoutemo.connector.GetPostsService.java
/** * *//* ww w .j a v a 2 s . c om*/ private void startGetPostsTask() { mAccountManager.getAuthToken(mAccount, LoginActivity.PARAM_AUTHTOKEN_TYPE, null, false, new AccountManagerCallback<Bundle>() { @Override 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; } mAuthToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); Log.v(TAG, "Received authentication token=" + mAuthToken); // now get messages! if (worker == null || worker.isShutdown()) { worker = Executors.newSingleThreadScheduledExecutor(); } // fix (possible) wrong time-setting on autemo.com worker.execute(new SetTimezoneTask()); // only now recieve messages (with right time) worker.scheduleAtFixedRate(new GetPostsTask(), 0, INTERVAL, TimeUnit.MILLISECONDS); } }, 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/*w w w . jav a 2 s. c o m*/ 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.york.cs.services.SyncAdapter.SyncAdapterCB.java
/** * Called by the Android system in response to a request to run the sync * adapter. The work required to read data from the network, parse it, and * store it done here. Extending AbstractThreadedSyncAdapter ensures that * all methods within SyncAdapter run on a background thread. For this * reason, blocking I/O and other long-running tasks can be run * <em>in situ</em>, and you don't have to set up a separate thread for * them. ./*from w ww . j a v a 2 s .c o m*/ * * <p> * This is where we actually perform any work required to perform a sync. * {@link AbstractThreadedSyncAdapter} guarantees that this will be called * on a non-UI thread, so it is safe to peform blocking I/O here. * * <p> * The syncResult argument allows you to pass information back to the method * that triggered the sync. */ @Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.d(TAG, "onPerformSync for account"); // Building a print of the extras we got StringBuilder sb = new StringBuilder(); if (extras != null) { for (String key : extras.keySet()) { sb.append(key + "[" + extras.get(key) + "] "); } } Log.d(TAG, "onPerformSync for account[" + account.name + "]. Extras: " + sb.toString()); try { // Get the auth token for the current account and // the userObjectId, needed for creating items on Parse.com account String authToken = mAccountManager.blockingGetAuthToken(account, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, true); String userObjectId = mAccountManager.getUserData(account, AccountGeneral.USERDATA_USER_OBJ_ID); Log.d(TAG, "start sunc" + authToken + "-" + userObjectId); Application application = (Application) getContext(); Database database = application.getDatabase(); initObservable(); startSyncWithCustomCookie(database, authToken); } catch (OperationCanceledException e) { e.printStackTrace(); } catch (IOException e) { syncResult.stats.numIoExceptions++; e.printStackTrace(); } catch (AuthenticatorException e) { syncResult.stats.numAuthExceptions++; e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jnrain.mobile.ui.MainActivity.java
@Override public void run(AccountManagerFuture<Account[]> response) { Account[] accounts;/* w w w .j a v a 2s .co m*/ try { accounts = response.getResult(); if (accounts.length > 0) { onAccountAcquired(accounts[0]); return; } // no account // try to create one, but don't recurse infinitely if (GlobalState.getAccountInitLevel() > 2) { // finish self finish(); return; } // create account new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... arg0) { AccountManager am = AccountManager.get(getThisActivity()); try { am.addAccount(AccountConstants.ACCOUNT_TYPE_KBS, null, null, null, getThisActivity(), new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> response) { try { response.getResult(); } catch (OperationCanceledException e) { // TODO Auto-generated catch // block e.printStackTrace(); } catch (AuthenticatorException e) { // TODO Auto-generated catch // block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch // block e.printStackTrace(); } MainActivity.this.initAccount(); } }, null).getResult(); } catch (OperationCanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AuthenticatorException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }.execute((Void) null); } catch (OperationCanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); finish(); } catch (AuthenticatorException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
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. ja va 2 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:org.creativecommons.thelist.utils.ListUser.java
/** * Get auth token for existing account (assumes pre-existing account) *//*from w w w.ja v a 2s. com*/ public void getToken(final AuthCallback callback) { Log.d(TAG, "getToken > getting session token"); //sessionComplete = false; //TODO: match userID to account with the same userID store in AccountManager Account account = getAccount(); if (account == null) { Log.v(TAG, "getToken > getAccount > account is null"); return; } am.getAuthToken(account, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, null, mActivity, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bundle = future.getResult(); String authtoken = bundle.getString(AccountManager.KEY_AUTHTOKEN); Log.v(TAG, "> getToken, token received: " + authtoken); callback.onSuccess(authtoken); } catch (OperationCanceledException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (AuthenticatorException e) { e.printStackTrace(); } } }, null); }