List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:org.klnusbaum.udj.PlaylistLoader.java
private PlaylistResult attemptLoad(boolean attemptReauth) { AccountManager am = AccountManager.get(getContext()); String authToken = ""; try {/*from ww w . j a v a 2 s . c om*/ authToken = am.blockingGetAuthToken(account, "", true); } catch (IOException e) { //TODO this might actually be an auth error return new PlaylistResult(null, PlaylistLoadError.AUTHENTICATION_ERROR); } catch (AuthenticatorException e) { return new PlaylistResult(null, PlaylistLoadError.AUTHENTICATION_ERROR); } catch (OperationCanceledException e) { return new PlaylistResult(null, PlaylistLoadError.AUTHENTICATION_ERROR); } try { String playerId = am.getUserData(account, Constants.LAST_PLAYER_ID_DATA); JSONObject serverResult = ServerConnection.getActivePlaylist(playerId, authToken); List<ActivePlaylistEntry> toReturn = RESTProcessor.processActivePlaylist(serverResult, am, account, context); return new PlaylistResult(toReturn); } catch (JSONException e) { return new PlaylistResult(null, PlaylistLoadError.SERVER_ERROR); } catch (ParseException e) { return new PlaylistResult(null, PlaylistLoadError.SERVER_ERROR); } catch (IOException e) { return new PlaylistResult(null, PlaylistLoadError.SERVER_ERROR); } catch (AuthenticationException e) { if (attemptReauth) { Log.d(TAG, "soft auth failure"); am.invalidateAuthToken(Constants.ACCOUNT_TYPE, authToken); return attemptLoad(false); } else { Log.d(TAG, "hard auth failure"); return new PlaylistResult(null, PlaylistLoadError.AUTHENTICATION_ERROR); } } catch (PlayerInactiveException e) { return new PlaylistResult(null, PlaylistLoadError.PLAYER_INACTIVE_ERROR); } catch (NoLongerInPlayerException e) { return new PlaylistResult(null, PlaylistLoadError.NO_LONGER_IN_PLAYER_ERROR); } catch (KickedException e) { return new PlaylistResult(null, PlaylistLoadError.KICKED_ERROR); } }
From source file:com.pixmob.r2droid.SelectAccountActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.select_account); accountManager = AccountManager.get(this); accountAdapter = new AccountAdapter(this); setListAdapter(accountAdapter);//from w w w . j a v a2 s. c o m // get a previously started account verifier accountVerifier = (AccountVerifier) getLastNonConfigurationInstance(); if (accountVerifier != null) { // an account verifier is running // (the screen configuration may have changed): // attach this task to this context accountVerifier.context = this; } }
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 w w w . j a va 2 s .co m*/ 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.menumomma.chrome2phone.AppEngineClient.java
private HttpResponse makeRequestNoRetry(String urlPath, List<NameValuePair> params, boolean newToken) throws Exception { // Get auth token for account Account account = new Account(mAccountName, "com.google"); String authToken = getAuthToken(mContext, account); if (newToken) { // invalidate the cached token AccountManager accountManager = AccountManager.get(mContext); accountManager.invalidateAuthToken(account.type, authToken); authToken = getAuthToken(mContext, account); }/* w ww . j a v a 2s . c o m*/ // Get ACSID cookie DefaultHttpClient client = new DefaultHttpClient(); String continueURL = Config.BASE_URL; URI uri = new URI(AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken); HttpGet method = new HttpGet(uri); final HttpParams getParams = new BasicHttpParams(); HttpClientParams.setRedirecting(getParams, false); // continue is not used method.setParams(getParams); HttpResponse res = client.execute(method); Header[] headers = res.getHeaders("Set-Cookie"); if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) { return res; } String ascidCookie = null; for (Header header : headers) { if (header.getValue().indexOf("ACSID=") >= 0) { // let's parse it String value = header.getValue(); String[] pairs = value.split(";"); ascidCookie = pairs[0]; } } // Make POST request uri = new URI(Config.BASE_URL + urlPath); HttpPost post = new HttpPost(uri); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); post.setEntity(entity); post.setHeader("Cookie", ascidCookie); post.setHeader("X-Same-Domain", "1"); // XSRF res = client.execute(post); return res; }
From source file:com.sintef_energy.ubisolar.adapter.UsageSyncAdapter.java
public UsageSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); mAccountManager = AccountManager.get(context); }
From source file:com.york.cs.services.SyncAdapter.SyncAdapterCB.java
/** * Constructor. Obtains handle to content resolver for later use. *//*from www . j av a 2 s . co m*/ public SyncAdapterCB(Context context, boolean autoInitialize) { super(context, autoInitialize); mAccountManager = AccountManager.get(context); mContentResolver = context.getContentResolver(); }
From source file:com.browsertophone.AppEngineClient.java
private HttpResponse makeRequestNoRetry(String urlPath, List<NameValuePair> params, boolean newToken) throws Exception { // Get auth token for account Account account = new Account(mAccountName, "com.google"); String authToken = getAuthToken(mContext, account); if (authToken == null) throw new PendingAuthException(mAccountName); if (newToken) { // invalidate the cached token AccountManager accountManager = AccountManager.get(mContext); accountManager.invalidateAuthToken(account.type, authToken); authToken = getAuthToken(mContext, account); }/*from w w w .ja va 2 s . co m*/ // Get ACSID cookie DefaultHttpClient client = new DefaultHttpClient(); String continueURL = BASE_URL; URI uri = new URI(AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken); HttpGet method = new HttpGet(uri); final HttpParams getParams = new BasicHttpParams(); HttpClientParams.setRedirecting(getParams, false); // continue is not used method.setParams(getParams); HttpResponse res = client.execute(method); Header[] headers = res.getHeaders("Set-Cookie"); if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) { return res; } String ascidCookie = null; for (Header header : headers) { if (header.getValue().indexOf("ACSID=") >= 0) { // let's parse it String value = header.getValue(); String[] pairs = value.split(";"); ascidCookie = pairs[0]; } } // Make POST request uri = new URI(BASE_URL + urlPath); HttpPost post = new HttpPost(uri); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); post.setEntity(entity); post.setHeader("Cookie", ascidCookie); post.setHeader("X-Same-Domain", "1"); // XSRF res = client.execute(post); return res; }
From source file:eu.e43.impeller.account.LoginActivity.java
@Override public void onCreate(Bundle icicle) { Log.v(TAG, "onCreate(" + icicle + ")"); super.onCreate(icicle); setContentView(R.layout.activity_login); m_accountManager = AccountManager.get(this); final Intent intent = getIntent(); String id = intent.getStringExtra("id"); m_idView = (TextView) findViewById(R.id.id); m_loginButton = (Button) findViewById(R.id.sign_in_button); m_loginFormView = findViewById(R.id.login_form); m_loginStatusView = findViewById(R.id.login_status); m_webView = (WebView) findViewById(R.id.web_view); m_idView.setText(id);// ww w . j a va2s.c om m_loginButton.setOnClickListener(this); m_webView.setWebViewClient(new WebViewListener()); }
From source file:com.skubit.android.billing.BillingServiceBinder.java
public BillingServiceBinder(Context context) { this.mContext = context; mPackageManager = mContext.getPackageManager(); mAccountSettings = AccountSettings.get(context); mAccountManager = AccountManager.get(context); }