List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public String readToken(Context ctx, String inAuthority) { final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority; AccountManager am = AccountManager.get(ctx); return am.peekAuthToken(new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)), authority);//from ww w.j a va 2s.c om }
From source file:com.ntsync.android.sync.activities.MainActivity.java
private void updateButtonState() { AccountManager accountManager = AccountManager.get(this); Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE); boolean accountAvailable = accounts != null && accounts.length > 0; this.findViewById(R.id.btnImport).setEnabled(accountAvailable); this.findViewById(R.id.btnAccount).setEnabled(accountAvailable); }
From source file:com.hotmart.dragonfly.ui.BaseActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); mAccountManager = AccountManager.get(getBaseContext()); }
From source file:de.stkl.gbgvertretungsplan.sync.SyncAdapter.java
public SyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); mAccountManager = AccountManager.get(context); mContext = context;//w w w .ja va2 s. c o m if (mComInterface == null) mComInterface = GBGCommunication.getInstance(); }
From source file:com.york.cs.services.SyncAdapter.SyncAdapterCB.java
public SyncAdapterCB(Context context, boolean autoInitialize, boolean allowParallelSyncs) { super(context, autoInitialize, allowParallelSyncs); mAccountManager = AccountManager.get(context); mContentResolver = context.getContentResolver(); }
From source file:com.owncloud.android.network.OwnCloudClientUtils.java
/** * Creates a WebdavClient setup for an ownCloud account * /*from w w w.j ava 2s.c o m*/ * Do not call this method from the main thread. * * @param account The ownCloud account * @param appContext Android application context * @return A WebdavClient object ready to be used * @throws AuthenticatorException If the authenticator failed to get the authorization token for the account. * @throws OperationCanceledException If the authenticator operation was cancelled while getting the authorization token for the account. * @throws IOException If there was some I/O error while getting the authorization token for the account. * @throws AccountNotFoundException If 'account' is unknown for the AccountManager */ public static WebdavClient createOwnCloudClient(Account account, Context appContext) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException { //Log_OC.d(TAG, "Creating WebdavClient associated to " + account.name); Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account)); AccountManager am = AccountManager.get(appContext); boolean isOauth2 = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here boolean isSamlSso = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO) != null; WebdavClient client = createOwnCloudClient(uri, appContext, !isSamlSso); if (isOauth2) { String accessToken = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN, false); client.setBearerCredentials(accessToken); // TODO not assume that the access token is a bearer token } else if (isSamlSso) { // TODO avoid a call to getUserData here String accessToken = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE, false); client.setSsoSessionCookie(accessToken); } else { String username = account.name.substring(0, account.name.lastIndexOf('@')); //String password = am.getPassword(account); String password = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD, false); client.setBasicCredentials(username, password); } return client; }
From source file:app.hacked.ChatFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); queue = Volley.newRequestQueue(getActivity()); AccountManager am = AccountManager.get(getActivity()); accounts = am.getAccountsByType("com.google"); //chatMessages = new ArrayList<ChatMessage>(); }
From source file:com.google.android.apps.chrometophone.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 w w.j a v a2s . c o m DefaultHttpClient client = new DefaultHttpClient(); String baseUrl; URI uri; String ascidCookie = null; HttpResponse res; if (BASE_LOCAL_URL == null) { // Get ACSID cookie so it can be used to authenticate on AppEngine String continueURL = BASE_URL; 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); res = client.execute(method); Header[] headers = res.getHeaders("Set-Cookie"); if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) { return res; } 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]; } } baseUrl = BASE_URL; } else { // local app server, pass user directly baseUrl = BASE_LOCAL_URL; params.add(new BasicNameValuePair("account", account.name)); } // Make POST request uri = new URI(baseUrl + urlPath); HttpPost post = new HttpPost(uri); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); post.setEntity(entity); if (ascidCookie != null) { post.setHeader("Cookie", ascidCookie); } post.setHeader("X-Same-Domain", "1"); // XSRF res = client.execute(post); return res; }
From source file:com.ntsync.android.sync.activities.VerifyPaymentProgressDialog.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments();/* w ww. ja v a 2 s . c o m*/ String priceId = args.getString(PARAM_PRICEID); String jsonProofOfPayment = args.getString(PARAM_PROOFOFPAYMENT); String accountName = args.getString(PARAM_ACCOUNTNAME); AccountManager acM = AccountManager.get(this.getActivity()); Account account = new Account(accountName, Constants.ACCOUNT_TYPE); // Retain to keep Task during conf changes setRetainInstance(true); setCancelable(false); verifyTask = new VerifyPaymentTask(priceId, jsonProofOfPayment, account, acM); verifyTask.execute(); }
From source file:com.rukman.emde.smsgroups.authenticator.GMSAuthenticator.java
@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { Log.d(TAG, "Get Auth Token"); // If the caller requested an authToken type we don't support, then // return an error if (!authTokenType.equals(GMSApplication.AUTHTOKEN_TYPE)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; }//from ww w . ja va 2 s.co m // Extract the username and password from the Account Manager, and ask // the server for an appropriate AuthToken. final String password = AccountManager.get(mContext).getPassword(account); if (!TextUtils.isEmpty(password)) { try { final String authToken = NetworkUtilities.authenticate(account.name, password); if (!TextUtils.isEmpty(authToken)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, GMSApplication.ACCOUNT_TYPE); result.putString(AccountManager.KEY_AUTHTOKEN, authToken); return result; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } // If we get here, then we couldn't access the user's password - so we // need to re-prompt them for their credentials. We do that by creating // an intent to display our AuthenticatorActivity panel. final Intent intent = new Intent(mContext, GMSAuthenticatorActivity.class); intent.putExtra(GMSAuthenticatorActivity.PARAM_USERNAME, account.name); intent.putExtra(GMSAuthenticatorActivity.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; }