List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:edu.vu.isis.ammo.dash.provider.IncidentSyncAdaptor.java
public IncidentSyncAdaptor(Context context, boolean autoInitialize) { super(context, autoInitialize); this.context = context; accountManager = AccountManager.get(context); this.lastUpdate = new Date(); }
From source file:com.battlelancer.seriesguide.ui.ConnectTraktCredentialsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setupViews();/*from ww w . j a va2 s . com*/ // unfinished task around? if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED) { // disable buttons, show status message setButtonStates(false, false); setStatus(true, true, R.string.waitplease); } // enable e-mail completion via device accounts final Account[] accounts = AccountManager.get(getActivity()).getAccounts(); final Set<String> emailSet = new HashSet<>(); for (Account account : accounts) { if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { emailSet.add(account.name); } } List<String> emails = new ArrayList<>(emailSet); mEmailAutoCompleteView.setAdapter( new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line, emails)); // connect button mButtonConnect.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // disable buttons, show status message setButtonStates(false, false); setStatus(true, true, R.string.waitplease); // get username and password Editable editableUsername = mEditTextUsername.getText(); String username = editableUsername != null ? editableUsername.toString().trim() : null; Editable editablePassword = mEditTextPassword.getText(); String password = editablePassword != null ? editablePassword.toString().trim() : null; // get email String email = null; if (mCheckBoxNewAccount.isChecked()) { Editable editableEmail = mEmailAutoCompleteView.getText(); email = editableEmail != null ? editableEmail.toString().trim() : null; } mTask = new ConnectTraktTask(getActivity().getApplicationContext(), ConnectTraktCredentialsFragment.this); mTask.execute(username, password, email); } }); // disconnect button mButtonDisconnect.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO do this async TraktCredentials.get(getActivity()).removeCredentials(); setupViews(); } }); }
From source file:com.browsertophone.AppEngineClient.java
private String getAuthToken(Context context, Account account) { String authToken = null;//from w w w .j a va2 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); // User will be asked for "App Engine" permission. if (authToken == null) { // No auth token - will need to ask permission from user. Intent intent = new Intent(SetupActivity.AUTH_PERMISSION_ACTION); 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.google.cloud.solutions.smashpix.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); createImageStorageDirectory();// w w w. jav a 2 s. c o m setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Logger.getLogger(LOGGER_NAME).setLevel(Constants.LOGGING_LEVEL); AccountManager accountManager = AccountManager.get(this); Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE); accountName = accounts[0].name; credential = GoogleAccountCredential.usingAudience(this, AUDIENCE_NAMESPACE + Constants.WEB_CLIENT_ID); credential.setSelectedAccountName(accountName); Image.Builder builder = new Image.Builder( AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential); builder.setApplicationName(Constants.APP_NAME); service = builder.build(); listImages(); }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.ChannelService.java
private static String getRegistrationId(Context context) { Account ac = AccountUtils.getAccount(context, false); if (ac == null) { log.warn("Cannot get account"); return ""; }/* w w w . jav a 2 s. c o m*/ AccountManager am = AccountManager.get(context); String regID = am.getUserData(ac, JsonKeys.GCM_ID); if (regID == null) { regID = ""; } return regID; }
From source file:sg.macbuntu.android.pushcontacts.DeviceRegistrar.java
private static String getAuthToken(Context context, Account account) { String authToken = null;/*from www. j a v a 2 s .c om*/ 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); // User will be asked for "App Engine" permission. if (authToken == null) { // No auth token - will need to ask permission from user. Intent intent = new Intent(ActivityUI.AUTH_PERMISSION_ACTION); 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.cyanogenmod.account.util.CMAccountUtils.java
public static Account getCMAccountAccount(Context context) { final AccountManager am = AccountManager.get(context); Account[] accounts = am.getAccountsByType(CMAccount.ACCOUNT_TYPE_CMAccount); return accounts.length > 0 ? accounts[0] : null; }
From source file:edu.mit.mobile.android.locast.sync.LocastSyncService.java
@Override public void onCreate() { super.onCreate(); AccountManager.get(this).addOnAccountsUpdatedListener(getSyncAdapter(), null, true); }
From source file:com.nononsenseapps.notepad.sync.SyncAdapter.java
public SyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); mContext = context;//from w w w.ja va 2 s . c om // mAccountManager = AccountManager.get(context); accountManager = AccountManager.get(context); }
From source file:com.phonemetra.account.util.AccountUtils.java
public static Account getAccountAccount(Context context) { final AccountManager am = AccountManager.get(context); Account[] accounts = am.getAccountsByType(Account.ACCOUNT_TYPE_Account); return accounts.length > 0 ? accounts[0] : null; }