List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "onCreate()"); // getWindow().requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.conflict_resolver); mAccountManager = AccountManager.get(this); final Map<String, ISweetContact> localContacts = new HashMap<String, ISweetContact>(); final Map<String, ISweetContact> sugarContacts = new HashMap<String, ISweetContact>(); try {/* w w w .j a v a2 s.co m*/ retreiveConflicts(localContacts, sugarContacts); } catch (Exception ex) { Log.e(TAG, "This shouldn't happen " + ex.getMessage()); ex.printStackTrace(); quitResolver(); } final TableLayout fieldTable = (TableLayout) findViewById(R.id.fieldTable); mButtonPrevConflict = (Button) findViewById(R.id.buttonPreviousConflict); mButtonNextConflict = (Button) findViewById(R.id.buttonNextConflict); Button buttonCancel = (Button) findViewById(R.id.buttonCancel); Button buttonResolve = (Button) findViewById(R.id.buttonResolve); mAccount = getIntent().getParcelableExtra("account"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); mPreferServer = settings.getBoolean(this.getString(R.string.prefer_server_resolve), false); task = (SyncResolvedContactsTask) getLastNonConfigurationInstance(); if (task == null) { task = new SyncResolvedContactsTask(this, mAccountManager, mAccount, getString(R.string.account_type)); } else { task.attach(this); } buttonCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { quitResolver(); } }); buttonResolve.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { doResolve(); } }); if ((localContacts.size() >= 0) && (sugarContacts.size() == localContacts.size())) { mConflictSet = new ArrayList<String>(localContacts.keySet()); createResolvedContactsArray(localContacts, sugarContacts); mPosResolved = 0; mCurrentId = mConflictSet.get(mPosResolved); displayConflict(localContacts, sugarContacts, fieldTable); mButtonNextConflict.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if ((mPosResolved < mConflictSet.size()) && (mPosResolved < resolvedContacts.length)) { mPosResolved++; mCurrentId = mConflictSet.get(mPosResolved); displayConflict(localContacts, sugarContacts, fieldTable); } } }); mButtonPrevConflict.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mPosResolved > 0) { mPosResolved--; mCurrentId = mConflictSet.get(mPosResolved); displayConflict(localContacts, sugarContacts, fieldTable); } } }); } else { quitResolver(); return; } }
From source file:edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticator.java
/** * {@inheritDoc}/*from w w w. j a va2 s . c o m*/ */ @Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) { if (!authTokenType.equals(getAuthTokenType())) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; } final AccountManager am = AccountManager.get(mContext); final String password = am.getPassword(account); if (password != null) { final Bundle accountData = onlineConfirmPassword(account, password); if (accountData != null) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, getAccountType()); result.putString(AccountManager.KEY_AUTHTOKEN, password); return result; } } // the password was missing or incorrect, return an Intent to an // Activity that will prompt the user for the password. final Intent intent = getAuthenticator(mContext); intent.putExtra(AbsLocastAuthenticatorActivity.EXTRA_USERNAME, account.name); intent.putExtra(AbsLocastAuthenticatorActivity.EXTRA_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:com.coloreight.plugin.socialAuth.SocialAuth.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; accountManager = AccountManager.get(this.cordova.getActivity().getApplicationContext()); if (action.equals("canUseTwitterSystemAccount")) { this.canUseTwitterSystemAccount(callbackContext); } else if (action.equals("getTwitterSystemAccounts")) { this.getTwitterSystemAccounts(callbackContext); } else if (action.equals("getTwitterSystemAccount")) { this.getTwitterSystemAccount(args.getString(0), callbackContext); } else if (action.equals("setFacebookApp")) { this.setFacebookApp(args.getJSONObject(0), callbackContext); } else if (action.equals("getFacebookAccount")) { this.getFacebookAccount(args.getJSONObject(0), args.getString(1), callbackContext); } else {/*from w w w . j a va2s. com*/ Log.d(TAG, "invalid/na social auth method: " + action); callbackContext.error("invalid/na social auth method: " + action); return false; } return true; }
From source file:com.prestomation.android.androidfiledrop.AppEngineClient.java
public String getASCIDCookie(boolean https) 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); }// w w w . jav a2 s . c om AccountManager accountManager = AccountManager.get(mContext); accountManager.invalidateAuthToken(account.type, authToken); authToken = getAuthToken(mContext, account); // Get ACSID cookie DefaultHttpClient client = new DefaultHttpClient(); String continueURL = BASE_URL; String sURI = AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken; if (https == false) { sURI = sURI.replace("https", "http"); } URI uri = new URI(sURI); 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.toString(); } 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]; } } Log.i("AndroidFileDrop", "Received ASCIDCookie: " + ascidCookie); return ascidCookie; }
From source file:com.lvlstudios.android.gtmessage.AppEngineClient.java
private String getAuthToken(Context context, Account account) throws PendingAuthException { String authToken = null;/* w ww.jav a2 s . c o m*/ AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); if (authToken == null) { throw new PendingAuthException(bundle); } } catch (OperationCanceledException e) { Log.w(TAG, "AppEngineClient.getAuthToken " + e); } catch (AuthenticatorException e) { Log.w(TAG, "AppEngineClient.getAuthToken " + e); } catch (IOException e) { Log.w(TAG, "AppEngineClient.getAuthToken " + e); } return authToken; }
From source file:com.gelakinetic.inboxwidget.InboxCheckerAppWidgetConfigure.java
/** * Start the process to get all Inbox accounts. Will call onAccountResults() when the accounts * are retrieved./* w w w . jav a2s. 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); }
From source file:com.agiro.scanner.android.AppEngineClient.java
private String getAuthToken(Context context, Account account) { String authToken = null;//from w ww. j a v a 2 s. c o m AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); Account[] accs = accountManager.getAccounts(); Log.v(TAG, "Account size = " + accs.length); Log.v(TAG, "Listing accounts"); for (Account acc : accs) { Log.v(TAG, "Account: " + acc); } authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { Log.e(TAG, "No authToken"); // No auth token - will need to ask permission from user. Intent intent = new Intent("com.google.ctp.AUTH_PERMISSION"); intent.putExtra("AccountManagerBundle", bundle); context.sendBroadcast(intent); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.meiste.greg.ptw.GAE.java
public List<String> getGoogleAccounts() { final ArrayList<String> result = new ArrayList<String>(); final Account[] accounts = AccountManager.get(mContext).getAccountsByType(ACCOUNT_TYPE); for (final Account account : accounts) { result.add(account.name);/*from www .java 2s. c om*/ } return result; }
From source file:com.jefftharris.passwdsafe.sync.owncloud.OwncloudProvider.java
@Override public void unlinkAccount() { saveCertAlias(null, getContext());/* w w w . jav a 2 s .co m*/ saveAuthData(null, null); updateOwncloudAcct(); AccountManager acctMgr = AccountManager.get(getContext()); acctMgr.invalidateAuthToken(SyncDb.OWNCLOUD_ACCOUNT_TYPE, AccountTypeUtils.getAuthTokenTypePass(SyncDb.OWNCLOUD_ACCOUNT_TYPE)); }
From source file:org.pixmob.appengine.client.AppEngineClient.java
/** * Create a new instance. No account is set: the method * {@link #setAccount(String)} must be called prior to executing a request. * @param context used for getting services and starting intents * @param appEngineHost hostname where the AppEngine is hosted * @param delegate {@link HttpClient} instance for making HTTP requests *//*from ww w . j a va 2 s.c om*/ public AppEngineClient(final Context context, final String appEngineHost, final HttpClient delegate) { this.context = context.getApplicationContext(); this.appEngineHost = appEngineHost; delegateWasSet = delegate != null; this.delegate = delegateWasSet ? delegate : SSLEnabledHttpClient.newInstance(HTTP_USER_AGENT); accountManager = AccountManager.get(context); loginClient = SSLEnabledHttpClient.newInstance(HTTP_USER_AGENT); loginClient.setCookieStore(new BasicCookieStore()); loginClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); setRetryCount(3); }