List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:com.example.am.myapplication.ContactAdder.java
/** * Updates account list spinner when the list of Accounts on the system changes. Satisfies * OnAccountsUpdateListener implementation. *//*from w w w .ja v a 2 s . com*/ public void onAccountsUpdated(Account[] a) { Log.i(TAG, "Account list update detected"); // Clear out any old data to prevent duplicates mAccounts.clear(); // Get account data from system AuthenticatorDescription[] accountTypes = AccountManager.get(this).getAuthenticatorTypes(); // Populate tables for (int i = 0; i < a.length; i++) { // The user may have multiple accounts with the same name, so we need to construct a // meaningful display name for each. String systemAccountType = a[i].type; AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType, accountTypes); AccountData data = new AccountData(a[i].name, ad); mAccounts.add(data); } // Update the account spinner mAccountAdapter.notifyDataSetChanged(); }
From source file:com.jedi.setupwizard.ui.SetupWizardActivity.java
public void launchGoogleAccountSetup() { Bundle bundle = new Bundle(); bundle.putBoolean(SetupWizard.EXTRA_FIRST_RUN, true); bundle.putBoolean(SetupWizard.EXTRA_ALLOW_SKIP, true); AccountManager.get(this).addAccount(SetupWizard.ACCOUNT_TYPE_GOOGLE, null, null, bundle, this, new AccountManagerCallback<Bundle>() { @Override// www .j a va 2 s. c o m public void run(AccountManagerFuture<Bundle> bundleAccountManagerFuture) { if (isDestroyed()) return; //There is a change this activity has been torn down. String token = null; try { token = bundleAccountManagerFuture.getResult().getString(AccountManager.KEY_AUTHTOKEN); mGoogleAccountSetupComplete = true; Page page = mPageList.findPage(R.string.setup_google_account); if (page != null) { onPageFinished(page); } } catch (OperationCanceledException e) { } catch (IOException e) { } catch (AuthenticatorException e) { } } }, null); }
From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java
/** * Internal constructor that only performs initial parsing. *///from w w w . ja v a2 s . c o m public AccountTypeManagerImpl(Context context) { mContext = context; mFallbackAccountType = new FallbackAccountType(context); mAccountManager = AccountManager.get(mContext); mListenerThread = new HandlerThread("AccountChangeListener"); mListenerThread.start(); mListenerHandler = new Handler(mListenerThread.getLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case MESSAGE_LOAD_DATA: loadAccountsInBackground(); break; case MESSAGE_PROCESS_BROADCAST_INTENT: processBroadcastIntent((Intent) msg.obj); break; } } }; mInvitableAccountTypeCache = new InvitableAccountTypeCache(); // Request updates when packages or accounts change IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); filter.addDataScheme("package"); mContext.registerReceiver(mBroadcastReceiver, filter); IntentFilter sdFilter = new IntentFilter(); sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); mContext.registerReceiver(mBroadcastReceiver, sdFilter); // Request updates when locale is changed so that the order of each field will // be able to be changed on the locale change. filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED); mContext.registerReceiver(mBroadcastReceiver, filter); if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } mAccountManager.addOnAccountsUpdatedListener(this, mListenerHandler, false); ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this); mListenerHandler.sendEmptyMessage(MESSAGE_LOAD_DATA); }
From source file:com.jefftharris.passwdsafe.sync.owncloud.OwncloudProvider.java
/** * Get the ownCloud authentication for an account. A notification may be * presented if authorization is required. Must be called from a background * thread.//from www .ja v a2 s . c o m */ @SuppressWarnings("deprecation") private static String getAuthToken(Account account, Context ctx, Activity activity) { String authToken = null; try { AccountManager acctMgr = AccountManager.get(ctx); String authType = AccountTypeUtils.getAuthTokenTypePass(SyncDb.OWNCLOUD_ACCOUNT_TYPE); AccountManagerFuture<Bundle> fut; if ((activity != null) && ApiCompat.canAccountMgrGetAuthTokenWithDialog()) { fut = acctMgr.getAuthToken(account, authType, null, activity, null, null); } else { fut = acctMgr.getAuthToken(account, authType, true, null, null); } Bundle b = fut.getResult(60, TimeUnit.SECONDS); authToken = b.getString(AccountManager.KEY_AUTHTOKEN); } catch (Throwable e) { PasswdSafeUtil.dbginfo(TAG, e, "getAuthToken"); } PasswdSafeUtil.dbginfo(TAG, "getAuthToken: %b", (authToken != null)); return authToken; }
From source file:com.einzig.ipst2.activities.MainActivity.java
/** * Get user account if the user has already logged in. * * @return Account user logged in on.// w w w . ja v a 2 s. c o m */ private Account getAccount() { PreferencesHelper helper = new PreferencesHelper(getApplicationContext()); String email = helper.get(helper.emailKey()); Logger.i("Getting account " + email); AccountManager manager = AccountManager.get(this); for (Account account : manager.getAccounts()) { if (account.name.equalsIgnoreCase(email) && account.type.equalsIgnoreCase("com.google")) return account; } Logger.d("returning null account"); return null; }
From source file:com.android.settings.locationprivacy.LocationPrivacyAdvancedSettings.java
private void refresh() { for (int i = 0; i < screen.getPreferenceCount(); i++) { Preference pref = screen.getPreference(i); if (pref != null) { System.out.println(pref); String key = pref.getKey(); if (key != null) { System.out.println(key); if (key.equals("lp_settings_advanced_useonlinealgorithm")) { CheckBoxPreference checkPref = (CheckBoxPreference) pref; checkPref.setChecked(lpManager.isUseOnlineAlgorithm()); } else if (key.equals("lp_settings_advanced_shareprivacyaettings")) { CheckBoxPreference checkPref = (CheckBoxPreference) pref; checkPref.setChecked(lpManager.isSharePrivacySettings()); checkPref.setEnabled(GooglePlayServicesUtil .isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS && lpManager.isWebhostShareSettings() && AccountManager.get(getActivity()).getAccountsByType("com.google").length >= 1); } else if (key.equals("lp_settings_advanced_showcommunityadvice")) { CheckBoxPreference checkPref = (CheckBoxPreference) pref; checkPref.setChecked(lpManager.isShowCommunityAdvice()); checkPref.setEnabled(lpManager.isShowCommunityAdvice()); } else if (key.equals("lp_settings_advanced_stars")) { CheckBoxPreference checkPref = (CheckBoxPreference) pref; checkPref.setChecked(lpManager.isUseStarsInDialog()); } else if (key.equals("lp_settings_advanced_webservice")) { EditTextPreference editTextPref = (EditTextPreference) pref; editTextPref.setText("" + lpManager.getWebserviceHostAdress()); } else if (key.equals("lp_settings_advanced_setpreset_min")) { EditTextPreference editTextPref = (EditTextPreference) pref; editTextPref.setText("" + lpManager.getMinDistance()); }//w ww . j a v a 2 s .c om pref.setOnPreferenceChangeListener(this); pref.setOnPreferenceClickListener(this); } } } }
From source file:com.github.opengarageapp.activity.MainActivity.java
public void getAuthAndDo(String intent) { Account account = application.getSelectedAccount(); AccountManager manager = AccountManager.get(this); manager.getAuthToken(account, "oauth2:https://www.googleapis.com/auth/userinfo.email", new Bundle(), this, new GarageActionAuthCallback(intent), null); }
From source file:net.vleu.par.android.rpc.Transceiver.java
/** * Invalidates the {@link GoogleAuthToken} stored in the * {@link AccountManager}/*from w w w .j a va2 s .c om*/ */ private void invalidatesGoogleAuthToken(final GoogleAuthToken token) { if (token != null) { final AccountManager am = AccountManager.get(this.context); if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Invalidating GoogleAuthToken : " + token.value); am.invalidateAuthToken(GOOGLE_ACCOUNT_TYPE, token.value); } }
From source file:com.github.opengarageapp.activity.MainActivity.java
public void invalidateAuthToken() { AccountManager manager = AccountManager.get(this); manager.invalidateAuthToken("com.google", application.getAuthToken()); }