List of usage examples for android.accounts Account toString
public String toString()
From source file:de.spiritcroc.syncsettings.Util.java
public static Account getAccountFromIntent(Context context, Intent intent) { if (intent.hasExtra(Constants.EXTRA_ACCOUNT_STRING)) { String accountString = intent.getStringExtra(Constants.EXTRA_ACCOUNT_STRING); Account[] accounts = AccountManager.get(context.getApplicationContext()).getAccounts(); for (Account account : accounts) { if (account.toString().equals(accountString)) { return account; }/*from w w w. ja v a 2 s .c o m*/ } Log.i(LOG_TAG, "getAccountFromIntent: could not recover account " + accountString); return null; } else if (intent.hasExtra(Constants.EXTRA_ACCOUNT)) { // Compatibility with intents from app with versionCode <= 2 Log.d(LOG_TAG, "getAccountFromIntent: Use old way to get account from intent"); return intent.getParcelableExtra(Constants.EXTRA_ACCOUNT); } else { Log.d(LOG_TAG, "getAccountFromIntent: No account extra found in intent"); return null; } }
From source file:com.martineve.mendroid.sync.MendeleySyncAdapter.java
private static void performSync(Context context, Application app, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) throws OperationCanceledException { Log.i(TAG, "Performing sync for account: " + account.toString()); mContentResolver = context.getContentResolver(); AccountManager am = AccountManager.get(app); AccountManagerCB AMC = new AccountManagerCB(app); Log.i(TAG, "Retrieving auth token."); am.getAuthToken(account, "com.martineve.mendroid.account", true, AMC, null); }
From source file:org.jnrain.mobile.ui.MainActivity.java
@SuppressWarnings("unchecked") public void onAccountAcquired(Account account) { Log.d(TAG, "Account info: " + account.toString()); String psw = AccountManager.get(this).getPassword(account); _loginHandler.sendMessage(new Message()); makeSpiceRequest(new KBSLoginRequest(account.name, psw), new KBSLoginRequestListener(this, account, account.name, psw)); }
From source file:com.mobiperf.speedometer.AccountSelector.java
/** Starts an authentication request */ public void authenticate() throws OperationCanceledException, AuthenticatorException, IOException { Logger.i("AccountSelector.authenticate() running"); /*//from w w w.ja va2 s . co m * We only need to authenticate every AUTHENTICATE_PERIOD_MILLI milliseconds, during which we * can reuse the cookie. If authentication fails due to expired authToken, the client of * AccountSelector can call authImmedately() to request authenticate() upon the next checkin */ long authTimeLast = this.getLastAuthTime(); long timeSinceLastAuth = System.currentTimeMillis() - authTimeLast; if (!this.shouldAuthImmediately() && authTimeLast != 0 && (timeSinceLastAuth < AUTHENTICATE_PERIOD_MSEC)) { return; } Logger.i("Authenticating. Last authentication is " + timeSinceLastAuth / 1000 / 60 + " minutes ago. "); AccountManager accountManager = AccountManager.get(context.getApplicationContext()); if (this.authToken != null) { // There will be no effect on the token if it is still valid Logger.i("Invalidating token"); accountManager.invalidateAuthToken(ACCOUNT_TYPE, this.authToken); } Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE); Logger.i("Got " + accounts.length + " accounts"); // get selected account SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context); String selectedAccount = prefs.getString(Config.PREF_KEY_SELECTED_ACCOUNT, null); if (accounts != null && accounts.length > 0 && selectedAccount != null) { Account accountToUse = null; for (Account account : accounts) { // if (account.name.toLowerCase().trim().endsWith(ACCOUNT_NAME)) { Logger.i("account list: " + account.name + " " + account.type + " " + account.toString()); // If one of the available accounts is the one selected by user, use that if (account.name.equals(selectedAccount)) { accountToUse = account; Logger.i("selected account: " + account.name + " " + account.type + " " + account.toString()); } } Logger.i("Trying to get auth token for " + accountToUse); AccountManagerFuture<Bundle> future = accountManager.getAuthToken(accountToUse, "ah", false, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> result) { Logger.i("AccountManagerCallback invoked"); try { getAuthToken(result); } catch (RuntimeException e) { Logger.e("Failed to get authToken", e); /* * TODO(Wenjie): May ask the user whether to quit the app nicely here if a number of * trials have been made and failed. Since Speedometer is basically useless without * checkin */ } } }, null); Logger.i("AccountManager.getAuthToken returned " + future); } else { throw new RuntimeException("No google account found or no google account selected"); } }
From source file:org.tigase.mobile.muc.JoinMucDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Dialog dialog = new Dialog(getActivity()); dialog.setCancelable(true);/*w w w.ja v a2s . co m*/ dialog.setCanceledOnTouchOutside(true); dialog.setContentView(R.layout.join_room_dialog); dialog.setTitle(getString(R.string.aboutButton)); ArrayList<String> accounts = new ArrayList<String>(); for (Account account : AccountManager.get(getActivity()).getAccountsByType(Constants.ACCOUNT_TYPE)) { accounts.add(account.name); } final Spinner accountSelector = (Spinner) dialog.findViewById(R.id.muc_accountSelector); final Button joinButton = (Button) dialog.findViewById(R.id.muc_joinButton); final Button cancelButton = (Button) dialog.findViewById(R.id.muc_cancelButton); final TextView name = (TextView) dialog.findViewById(R.id.muc_name); final TextView roomName = (TextView) dialog.findViewById(R.id.muc_roomName); final TextView mucServer = (TextView) dialog.findViewById(R.id.muc_server); final TextView nickname = (TextView) dialog.findViewById(R.id.muc_nickname); final TextView password = (TextView) dialog.findViewById(R.id.muc_password); final CheckBox autojoin = (CheckBox) dialog.findViewById(R.id.muc_autojoin); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, accounts.toArray(new String[] {})); accountSelector.setAdapter(adapter); Bundle data = getArguments(); final boolean editMode = data != null && data.containsKey("editMode") && data.getBoolean("editMode"); final String id = data != null ? data.getString("id") : null; if (data != null) { accountSelector.setSelection(adapter.getPosition(data.getString("account"))); name.setText(data.getString("name")); roomName.setText(data.getString("room")); mucServer.setText(data.getString("server")); nickname.setText(data.getString("nick")); password.setText(data.getString("password")); autojoin.setChecked(data.getBoolean("autojoin")); } if (!editMode) { name.setVisibility(View.GONE); autojoin.setVisibility(View.GONE); } else { joinButton.setText("Save"); } cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); joinButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (editMode) { BareJID account = BareJID.bareJIDInstance(accountSelector.getSelectedItem().toString()); final Jaxmpp jaxmpp = ((MessengerApplication) getActivity().getApplicationContext()) .getMultiJaxmpp().get(account); Bundle data = new Bundle(); data.putString("id", id); data.putString("account", account.toString()); data.putString("name", name.getText().toString()); data.putString("room", roomName.getText().toString()); data.putString("server", mucServer.getText().toString()); data.putString("nick", nickname.getText().toString()); data.putString("password", password.getText().toString()); data.putBoolean("autojoin", autojoin.isChecked()); ((BookmarksActivity) getActivity()).saveItem(data); dialog.dismiss(); return; } BareJID account = BareJID.bareJIDInstance(accountSelector.getSelectedItem().toString()); final Jaxmpp jaxmpp = ((MessengerApplication) getActivity().getApplicationContext()) .getMultiJaxmpp().get(account); Runnable r = new Runnable() { @Override public void run() { try { Room room = jaxmpp.getModule(MucModule.class).join( roomName.getEditableText().toString(), mucServer.getEditableText().toString(), nickname.getEditableText().toString(), password.getEditableText().toString()); if (task != null) task.execute(room); } catch (Exception e) { Log.w("MUC", "", e); // TODO Auto-generated catch block e.printStackTrace(); } } }; (new Thread(r)).start(); dialog.dismiss(); } }); return dialog; }