List of usage examples for android.accounts Account Account
public Account(@NonNull Account other, @NonNull String accessId)
From source file:com.clearcenter.mobile_demo.mdStatusActivity.java
public boolean onOptionsItemSelected(MenuItem item) { ContentResolver resolver = getContentResolver(); final Account account = new Account(account_nickname, mdConstants.ACCOUNT_TYPE); switch (item.getItemId()) { case R.id.menu_refresh: resolver.requestSync(account, mdContentProvider.AUTHORITY, new Bundle()); return true; case R.id.menu_reset: resetData();//from ww w. j a v a2s . c o m return true; } return false; }
From source file:com.skubit.android.transactions.TransactionsFragment.java
@Override public void onResume() { super.onResume(); String account = mAccountSettings.retrieveBitIdAccount(); if (!TextUtils.isEmpty(account)) { mTransactionService = new TransactionService(new Account(account, "com.google"), getActivity()); refreshBalance();//from w ww . j a v a 2s .c o m getTransactions(); } LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mAccountChangeReceiver, new IntentFilter("account")); }
From source file:com.newtifry.android.remote.BackendClient.java
private HttpResponse requestNoRetry(String urlPath, List<NameValuePair> params, boolean newToken) throws Exception { // Get auth token for account Account account = new Account(this.accountName, "com.google"); String authToken = getAuthToken(this.context, account); if (authToken == null) { throw new PendingAuthException(this.accountName); }//from www . j av a2s. c o m if (newToken) { // Invalidate the cached token AccountManager accountManager = AccountManager.get(this.context); accountManager.invalidateAuthToken(account.type, authToken); authToken = this.getAuthToken(this.context, account); } // Get ACSID cookie DefaultHttpClient client = new DefaultHttpClient(); String continueURL = getBackendURL(); // this.backendName; URI uri = new URI(getBackendURL() /* this.backendName */ + "/_ah/login?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken); HttpGet method = new HttpGet(uri); final HttpParams getParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(getParams, 5000); HttpConnectionParams.setSoTimeout(getParams, 5000); HttpClientParams.setRedirecting(getParams, false); // continue is not // used method.setParams(getParams); HttpResponse res = client.execute(method); Header[] headers = res.getHeaders("Set-Cookie"); 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]; } } res.getEntity().consumeContent(); // Make POST request uri = new URI(getBackendURL() /* this.backendName */ + 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.rowland.hashtrace.sync.TweetHashTracerSyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or * make a new one if the fake account doesn't exist yet. If we make a new * account, we call the onAccountCreated method so we can initialize things. * * @param context The context used to access the account service * @return a fake account.//from w w w . j a v a 2 s. com */ public static Account getSyncAccount(Context context) { // Get an instance of the Android account manager AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (null == accountManager.getPassword(newAccount)) { /* * Add the account and account type, no password or user data If * successful, return the Account object, otherwise report an error. */ if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } /* * If you don't set android:syncable="true" in in your <provider> * element in the manifest, then call * ContentResolver.setIsSyncable(account, AUTHORITY, 1) here. */ onAccountCreated(newAccount, context); } return newAccount; }
From source file:com.jefftharris.passwdsafe.sync.dropbox.DropboxCoreProvider.java
@Override public Account getAccount(String acctName) { return new Account(acctName, SyncDb.DROPBOX_ACCOUNT_TYPE); }
From source file:org.pixmob.droidlink.ui.AccountInitTask.java
@Override protected Integer doInBackground(String... params) { final String newAccount = params[0]; final String oldAccount = prefs.getString(SP_KEY_ACCOUNT, null); // Make sure this user has an unique device identifier. final boolean newUserSet = !prefs.contains(SP_KEY_DEVICE_ID) || !newAccount.equals(oldAccount); if (newUserSet) { prefsEditor.putString(SP_KEY_DEVICE_ID, DeviceUtils.getDeviceId(fragment.getActivity(), newAccount)); }//from w w w . j a v a 2s .c o m prefsEditor.putString(SP_KEY_ACCOUNT, newAccount); Features.getFeature(SharedPreferencesSaverFeature.class).save(prefsEditor); final NetworkClient client = NetworkClient.newInstance(fragment.getActivity()); int authResult = AUTH_FAIL; if (client != null) { final JSONObject data = new JSONObject(); try { data.put("name", prefs.getString(SP_KEY_DEVICE_NAME, null)); data.put("c2dm", prefs.getString(SP_KEY_DEVICE_C2DM, null)); client.put("/devices/" + client.getDeviceId(), data); authResult = AUTH_OK; } catch (AppEngineAuthenticationException e) { if (e.isAuthenticationPending()) { authPendingIntent = e.getPendingAuthenticationPermissionActivity(); authResult = AUTH_PENDING; } Log.w(TAG, "Failed to authenticate account", e); } catch (IOException e) { Log.w(TAG, "Failed to check account availability", e); } catch (JSONException e) { Log.w(TAG, "JSON error", e); } finally { client.close(); } } if (AUTH_OK == authResult) { if (newUserSet) { // The user is different: clear events. contentResolver.delete(EventsContract.CONTENT_URI, null, null); } prefsEditor.putString(SP_KEY_ACCOUNT, newAccount); // Enable synchronization only for our user. for (final Account account : accounts) { final boolean syncable = account.name.equals(newAccount); ContentResolver.setIsSyncable(account, EventsContract.AUTHORITY, syncable ? 1 : 0); } ContentResolver.setSyncAutomatically(new Account(newAccount, GOOGLE_ACCOUNT), EventsContract.AUTHORITY, true); } else { // Restore old account. prefsEditor.putString(SP_KEY_ACCOUNT, oldAccount); } Features.getFeature(SharedPreferencesSaverFeature.class).save(prefsEditor); if (AUTH_OK == authResult) { // Start synchronization. EventsContract.sync(getFragment().getActivity(), EventsContract.FULL_SYNC, null); } return authResult; }
From source file:eu.masconsult.bgbanking.activity.fragment.AccountsListFragment.java
private void populateList() { Log.v(TAG, "populateList"); // Create an empty adapter we will use to display the loaded data. mAdapter = new MergeAdapter(); accounts.clear();/*from w w w. jav a 2 s .com*/ adapters.clear(); // Prepare the loader. Either re-connect with an existing one, // or start a new one. Bank[] banks = Bank.values(); for (Bank bank : banks) { Account[] accounts = accountManager.getAccountsByType(bank.getAccountType(getActivity())); for (Account account : accounts) { addAccount(bank, account, false); } } if (accounts.size() == 0) { // show sample accounts for (Bank bank : banks) { addAccount(bank, new Account(getString(R.string.sample_account_name), bank.getAccountType(getActivity())), true); } } Log.v(TAG, String.format("found %d accounts", accounts.size())); setListAdapter(mAdapter); }
From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or make a new one * if the fake account doesn't exist yet. If we make a new account, we call the * onAccountCreated method so we can initialize things. * * @param context The context used to access the account service * @return a fake account.//w w w . j ava2 s . c om */ public static Account getSyncAccount(Context context) { //Log.d("Weather4USyncAdapter", "getSyncAccount"); // Get an instance of the Android account manager AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (null == accountManager.getPassword(newAccount)) { /* * Add the account and account type, no password or user data * If successful, return the Account object, otherwise report an error. */ if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } /* * If you don't set android:syncable="true" in * in your <provider> element in the manifest, * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1) * here. */ onAccountCreated(newAccount, context); } return newAccount; }
From source file:org.dmfs.tasks.SettingsListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); getLoaderManager().restartLoader(-2, null, this); mAdapter = new VisibleListAdapter(mContext, null, 0); List<Account> accounts = mSources.getExistingAccounts(); if (mContext.getResources().getBoolean(R.bool.org_dmfs_allow_local_lists)) { accounts.add(new Account(TaskContract.LOCAL_ACCOUNT_NAME, TaskContract.LOCAL_ACCOUNT_TYPE)); }/*from w w w. j a va 2 s. com*/ mAccountAdapter = new AccountAdapter(accounts); setListAdapter(mAdapter); getListView().setOnItemClickListener(this); }
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public String getAuthToken(Context ctx, String inAuthority, IntentSender intentSender) throws OperationCanceledException, AuthenticatorException, IOException { final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority; AccountManager am = AccountManager.get(ctx); AccountManagerFuture<Bundle> future = am.getAuthToken( new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)), authority, false, new OnTokenAcquired(ctx, authority, intentSender), null); String token = null;// ww w . j a v a 2 s . c o m if (future.isDone()) { token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); } return token; }