List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:com.zoterodroid.syncadapter.ContactSyncAdapter.java
public ContactSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); mContext = context; mAccountManager = AccountManager.get(context); }
From source file:com.ntsync.android.sync.activities.ViewKeyPasswordActivity.java
private void refreshAccountList() { FragmentManager mgr = getSupportFragmentManager(); AccountManager accountManager = AccountManager.get(this); Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE); FragmentTransaction trans = mgr.beginTransaction(); boolean isFirst = true; for (Account currAccount : accounts) { AccountFragment fragment = new AccountFragment(); Bundle args = new Bundle(); args.putString(AccountFragment.PARAM_ACCOUNT_NAME, currAccount.name); fragment.setArguments(args);/* w w w .j a va 2s . c om*/ if (isFirst) { trans.replace(R.id.accountContainer, fragment); isFirst = false; } else { trans.add(R.id.accountContainer, fragment); } } trans.commit(); }
From source file:com.bearstech.android.myownsync.syncadapter.SyncAdapter.java
public SyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); mContext = context; mAccountManager = AccountManager.get(context); }
From source file:com.nbos.phonebook.sync.syncadapter.SyncAdapter.java
public SyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); this.context = context; accountManager = AccountManager.get(context); }
From source file:com.android.volley.toolbox.AndroidAuthenticator.java
/** * Creates a new authenticator./*from w ww . j a v a 2 s . co m*/ * @param context Context for accessing AccountManager * @param account Account to authenticate as * @param authTokenType Auth token type passed to AccountManager * @param notifyAuthFailure Whether to raise a notification upon auth failure */ public AndroidAuthenticator(Context context, Account account, String authTokenType, boolean notifyAuthFailure) { this(AccountManager.get(context), account, authTokenType, notifyAuthFailure); }
From source file:com.kinvey.sample.signin.GoogleLoginActivity.java
/** Called when the activity is first created. */ @Override//w w w . j ava 2 s.c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.google_login); mKinveyClient = ((UserLogin) getApplication()).getKinveyService(); mAccountManager = AccountManager.get(this); Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[] { "com.google" }, false, null, null, null, null); startActivityForResult(intent, GPLAY_REQUEST_CODE); }
From source file:com.jefftharris.passwdsafe.sync.lib.AccountChooserDlg.java
@Override public @NonNull Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments();/*from ww w. j av a2s . com*/ String accountType = args.getString("accountType"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.choose_account); AccountManager acctMgr = AccountManager.get(getActivity()); Account[] accts = acctMgr.getAccountsByType(accountType); if (accts.length > 0) { final String[] names = new String[accts.length]; for (int i = 0; i < accts.length; ++i) { names[i] = accts[i].name; } builder.setItems(names, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { onAccountSelected(names[which]); } }); } else { builder.setMessage(args.getString("noAccountsMsg")); } AbstractDialogClickListener clickListener = new AbstractDialogClickListener() { @Override public void onCancelClicked() { onAccountSelected(null); } }; builder.setNegativeButton(R.string.cancel, clickListener); builder.setOnCancelListener(clickListener); return builder.create(); }
From source file:com.ocp.picasa.PicasaApi.java
public static Account[] getAccounts(Context context) { // Return the list of accounts supporting the Picasa GData service. AccountManager accountManager = AccountManager.get(context); Account[] accounts = {};// ww w .j av a 2 s. co m try { accounts = accountManager.getAccountsByTypeAndFeatures(PicasaService.ACCOUNT_TYPE, new String[] { PicasaService.FEATURE_SERVICE_NAME }, null, null).getResult(); } catch (OperationCanceledException e) { } catch (AuthenticatorException e) { } catch (IOException e) { } catch (Exception e) { ; } return accounts; }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync.java
/** * Returns true if sync was successful, false otherwise *//*from w w w. ja v a 2s . c o m*/ public static boolean fullSync(final Context context, final Account account, final Bundle extras, final String authority, final ContentProviderClient provider, final SyncResult syncResult) { Log.d(TAG, "fullSync"); // Is saved at a successful sync final long startTime = Calendar.getInstance().getTimeInMillis(); boolean success = false; // Initialize necessary stuff final AccountManager accountManager = AccountManager.get(context); final GoogleAPITalker apiTalker = new GoogleAPITalker(context); try { boolean connected = apiTalker.initialize(accountManager, account, AUTH_TOKEN_TYPE, NOTIFY_AUTH_FAILURE); if (connected) { Log.d(TAG, "AuthToken acquired, we are connected..."); try { // IF full sync, download since start of all time // Temporary fix for delete all bug // if (PreferenceManager.getDefaultSharedPreferences(context) // .getBoolean(SyncPrefs.KEY_FULLSYNC, false)) { PreferenceManager.getDefaultSharedPreferences(context).edit() .putBoolean(SyncPrefs.KEY_FULLSYNC, false).putLong(PREFS_GTASK_LAST_SYNC_TIME, 0) .commit(); // } // Download lists from server Log.d(TAG, "download lists"); final List<GoogleTaskList> remoteLists = downloadLists(apiTalker); // merge with local complement Log.d(TAG, "merge lists"); mergeListsWithLocalDB(context, account.name, remoteLists); // Synchronize lists locally Log.d(TAG, "sync lists locally"); final List<Pair<TaskList, GoogleTaskList>> listPairs = synchronizeListsLocally(context, remoteLists); // Synchronize lists remotely Log.d(TAG, "sync lists remotely"); final List<Pair<TaskList, GoogleTaskList>> syncedPairs = synchronizeListsRemotely(context, listPairs, apiTalker); // For each list for (Pair<TaskList, GoogleTaskList> syncedPair : syncedPairs) { // Download tasks from server Log.d(TAG, "download tasks"); final List<GoogleTask> remoteTasks = downloadChangedTasks(context, apiTalker, syncedPair.second); // merge with local complement Log.d(TAG, "merge tasks"); mergeTasksWithLocalDB(context, account.name, remoteTasks, syncedPair.first._id); // Synchronize tasks locally Log.d(TAG, "sync tasks locally"); final List<Pair<Task, GoogleTask>> taskPairs = synchronizeTasksLocally(context, remoteTasks, syncedPair); // Synchronize tasks remotely Log.d(TAG, "sync tasks remotely"); synchronizeTasksRemotely(context, taskPairs, syncedPair.second, apiTalker); } Log.d(TAG, "Sync Complete!"); success = true; PreferenceManager.getDefaultSharedPreferences(context).edit() .putLong(PREFS_GTASK_LAST_SYNC_TIME, startTime).commit(); /* * Tasks Step 1: Download changes from the server Step 2: * Iterate and compare with local content Step 2a: If both * versions changed, choose the latest Step 2b: If remote is * newer, put info in local task, save Step 2c: If local is * newer, upload it (in background) Step 3: For remote items * that do not exist locally, save Step 4: For local items * that do not exist remotely, upload */ } catch (ClientProtocolException e) { Log.e(TAG, "ClientProtocolException: " + e.getLocalizedMessage()); syncResult.stats.numAuthExceptions++; } catch (IOException e) { syncResult.stats.numIoExceptions++; Log.e(TAG, "IOException: " + e.getLocalizedMessage()); } catch (ClassCastException e) { // GetListofLists will cast this if it returns a string. // It should not return a string but it did... syncResult.stats.numAuthExceptions++; Log.e(TAG, "ClassCastException: " + e.getLocalizedMessage()); } } else { // return real failure Log.d(TAG, "Could not get authToken. Reporting authException"); syncResult.stats.numAuthExceptions++; // doneIntent.putExtra(SYNC_RESULT, LOGIN_FAIL); } } catch (Exception e) { // Something went wrong, don't punish the user syncResult.stats.numAuthExceptions++; Log.e(TAG, "bobs your uncle: " + e.getLocalizedMessage()); } finally { // This must always be called or we will leak resources if (apiTalker != null) { apiTalker.closeClient(); } Log.d(TAG, "SyncResult: " + syncResult.toDebugString()); } return success; }
From source file:info.dc585.hpt.sa.SyncAdapter.java
public SyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); mContext = context; accountManager = AccountManager.get(context); }