/** * Asks the user to add an account of a specified type. The authenticator * for this account type processes this request with the appropriate user * interface. If the user does elect to create a new account, the account * name is returned. * <p> * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * <p> * */ public AccountManagerFuture<Bundle> addAccount(final int userId, final String accountType, final String authTokenType, final String[] requiredFeatures, final Bundle addAccountOptions, final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) { if (accountType == null) throw new IllegalArgumentException("accountType is null"); final Bundle optionsIn = new Bundle(); if (addAccountOptions != null) { optionsIn.putAll(addAccountOptions); } optionsIn.putString(KEY_ANDROID_PACKAGE_NAME, "android"); return new AmsTask(activity, handler, callback) { @Override public void doWork() throws RemoteException { addAccount(userId, mResponse, accountType, authTokenType, requiredFeatures, activity != null, optionsIn); } }.start(); }
private void removeAccount(final Account account) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); sharedPreferences.edit().remove("queueName").apply(); ContentResolver.setIsSyncable(account, WEBINSTALL_SYNC_AUTHORITY, 0); ContentResolver.setSyncAutomatically(account, MyAccountActivity.WEBINSTALL_SYNC_AUTHORITY, false); if(Build.VERSION.SDK_INT>=8){ ContentResolver.removePeriodicSync(account, MyAccountActivity.WEBINSTALL_SYNC_AUTHORITY, new Bundle()); } mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> future) { addAccount(); finish(); } }, null); }
private void addAccount() { mAccountManager.addAccount(Aptoide.getConfiguration().getAccountType(), AptoideConfiguration.AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, null, null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bnd = future.getResult(); if (bnd.containsKey(AccountManager.KEY_AUTHTOKEN)) { setContentView(R.layout.form_logout); } else { finish(); } } catch (Exception e) { e.printStackTrace(); } } }, null); }
private void addNewAccount() { mAccountManager.addAccount(EnlightnsAccountAuthenticator.ACCOUNT_TYPE, EnlightnsAccountAuthenticator.AUTH_TOKEN_TYPE, null, null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bnd = future.getResult(); showMessage(getString(R.string.successful_login_toast)); new GetUserRecordsTask().execute(); Log.d(TAG, "AddNewAccount Bundle is " + bnd); } catch (OperationCanceledException oce) { Log.d(TAG, "Operation cancelled, no account available, exiting...", oce); finish(); } catch (Exception e) { Log.w(TAG, "Exception", e); showMessage(getString(R.string.login_error)); } } }, null); }
public void getAccessToken(String accountName, String authTokenType, Bundle options) { if (accountName == null || accountName.trim().isEmpty()) { Toast.makeText(context, context.getString(R.string.auth_msg_account_name_is_null), Toast.LENGTH_SHORT).show(); return; } Account account; if (options == null) { options = new Bundle(); } Handler handler = null; if (authTokenType == null) { authTokenType = authTokenTypes[0]; } else { if (!isAuthTokenValid(authTokenType, authTokenTypes)) throw new IllegalArgumentException("Authentication token type is not valid."); } if (isCallbackRunInBackgroundThread) handler = setHandler(CALLBACK_THREAD_NAME); account = new Account(accountName, accountType); AccountManagerCallback accountManagerCallback = null; boolean isAddingNewAccount = options.getBoolean(AuthenticatorManager.KEY_IS_ADDING_NEW_ACCOUNT, false); if (!isAddingNewAccount) { accountManagerCallback = getAccessTokenCallBack(authTokenType, options, account); } getAccessTokenFromAccountManager(account, authTokenType, options, accountManagerCallback, handler); }
private void fetchPioneerAccount() { String ACCOUNT_TYPE = "com.github.baoti"; String AUTH_TOKEN_TYPE = "pioneer"; accountManager.getAuthTokenByFeatures(ACCOUNT_TYPE, AUTH_TOKEN_TYPE, null, getView().getActivity(), null, null, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle result = future.getResult(); String name = result.getString(AccountManager.KEY_ACCOUNT_NAME); String type = result.getString(AccountManager.KEY_ACCOUNT_TYPE); String token = result.getString(AccountManager.KEY_AUTHTOKEN); toaster.show( String.format("Auth result - name: %s, type: %s, token: %s", name, type, token)); } catch (Exception e) { e.printStackTrace(); } } }, null); }
private void logout() { final Student currentStudent = UnicapApplication.getCurrentStudent(); if (currentStudent == null) { restartActivity(); } else { Account account = new Account(currentStudent.registration, AccountGeneral.ACCOUNT_TYPE); accountManager.removeAccount(account, new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> future) { UnicapDataManager.cleanUserData(currentStudent.registration); UnicapApplication.setCurrentAccount(null); UnicapApplication.setCurrentStudent(null); restartActivity(); } }, null); } }
/** * Removes current account */ private void removeAccount() { Timber.d("Removing account"); Account account = getAccount(); if (account != null) { isDeletingCredentials = true; accountManager.removeAccount(account, new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> future) { isDeletingCredentials = false; currentAccount = null; } }, null); } preferences.removeAllUserDetails(); friendsTable.deleteAll(); momentTable.deleteAll(); }
public String getToken() { // Get Account AccountManager manager = AccountManager.get(HomeScreenActivity.getAppContext()); Account account = manager.getAccountsByType("us.grahn.trojanow")[0]; // Get the auth token Bundle options = null; Activity activity = null; AccountManagerCallback<Bundle> callback = null; Handler handler = null; AccountManagerFuture<Bundle> future = manager.getAuthToken( account, AuthenticationService.AUTH_TYPE, options, activity, callback, handler); try { return future.getResult().getString(AccountManager.KEY_AUTHTOKEN); } catch(Exception e) { e.printStackTrace(); return null; } }
@Override public AccountManagerFuture<Bundle> getAuthToken(final AccountManagerCallback<Bundle> cb) { if (authInProgress.get()) { return new CanceledAccountManagerFuture<>(); } else { authInProgress.set(true); return AuthTokenGetHelper.getAuthTokenByFeatures(this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { if (cb != null) { cb.run(future); } authInProgress.set(false); } }); } }
/** * Logs out the account, keeping it on the device * @param account - the logged in {@link android.accounts.Account}. Must NOT be null * @param authTokenType - the auth token type. Must NOT be null or empty */ public void logout(@NonNull final Account account, @NonNull String authTokenType) { validateAccount(account); validateAccountName(account.name); validateAccountType(account.type); validateAuthTokenType(authTokenType); final String authToken = mAccountManager.peekAuthToken(account, authTokenType); final String accountType = account.type; mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> future) { if (!TextUtils.isEmpty(authToken)) { if (DEBUG) { Log.d(String.format(DEBUG_TAG, TAG), "Removing account with name " + account.name + " and type " + accountType + " from AccountManager and invalidating auth token " + authToken); } notifyCallbacksAuthenticationInvalidated(authToken); mAccountManager.invalidateAuthToken(accountType, authToken); } } }, new Handler(Looper.getMainLooper())); }
/** * Add new account to the account manager */ private void addNewAccount() { org.pimatic.model.AccountManager.getInstance(getActivity()).addNewAccount(this.getActivity(), new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bnd = future.getResult(); showMessage("Account was created"); Log.d("udinic", "AddNewAccount Bundle is " + bnd); } catch (Exception e) { e.printStackTrace(); showMessage(e.getMessage()); } } }); }
/** * Attempts to log out by removing the current Iodine account. * This method does not change state on the server. * After finishing, this method will call finish() on the passed activity. * @param activity The activity used as a context. */ public static void attemptLogout(@NonNull final Activity activity) { final AccountManager am = AccountManager.get(activity); final Account account = getIodineAccount(activity); final AccountManagerCallback<Boolean> callback = new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> future) { try { Boolean result = future.getResult(); if (!result) { throw new Exception("Result is false"); } } catch (Exception e) { Log.e(TAG, "Error trying to remove account", e); String message = activity.getString(R.string.error_removing_account, e.toString()); Toast.makeText(activity, message, Toast.LENGTH_SHORT).show(); return; } Log.i(TAG, "Successfully removed account."); Toast.makeText(activity, R.string.sign_out_success, Toast.LENGTH_LONG).show(); } }; am.removeAccount(account, callback, null); activity.finish(); }
public synchronized void queryGmailLabels() { // Get the account list, and pick the user specified address AccountManager.get(mContext).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 oce) { Logs.e(TAG, "Got OperationCanceledException: "+oce.toString()); } catch (IOException ioe) { Logs.e(TAG, "Got OperationCanceledException: "+ioe.toString()); } catch (AuthenticatorException ae) { Logs.e(TAG, "Got OperationCanceledException: "+ae.toString()); } mGmailUnreadCount = onAccountResults(accounts); addGmailToContentList(mGmailUnreadCount); Logs.d(TAG, "# Gmail unread count = "+ mGmailUnreadCount); } }, null /* handler */); }
private void getToken(final Account account, final int position) { AccountManager am = AccountManager.get(this); if (am == null) return; am.getAuthToken(account, "grandcentral", null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { settings.edit() .putString("account", account.name) .apply(); Intent intent = new Intent(SmackPlusSetup.this, SmackPlusService.class); intent.setAction(SmackPlusService.ACCOUNT_CHANGED); startService(intent); lv.setItemChecked(position, true); lv.requestLayout(); Log.i(LOGTAG, "Token retrieved."); } catch (Exception ex) { ex.printStackTrace(); } } }, new Handler()); }
public AmsTask(Activity activity, Handler handler, AccountManagerCallback<Bundle> callback) { super(new Callable<Bundle>() { @Override public Bundle call() throws Exception { throw new IllegalStateException("this should never be called"); } }); mHandler = handler; mCallback = callback; mActivity = activity; mResponse = new Response(); }
private void postToHandler(Handler handler, final AccountManagerCallback<Bundle> callback, final AccountManagerFuture<Bundle> future) { handler = handler == null ? VirtualRuntime.getUIHandler() : handler; handler.post(new Runnable() { @Override public void run() { callback.run(future); } }); }
/** * @see AccountManager#getAuthToken( * Account, String, Bundle, boolean, AccountManagerCallback, Handler) */ public AccountManagerFuture<Bundle> getAuthToken(final Account account, final String authTokenType, final Bundle options, final boolean notifyAuthFailure, final AccountManagerCallback<Bundle> callback, final Handler handler) { return mAccountManager.getAuthToken(account, authTokenType, options, notifyAuthFailure, callback, handler); }
@Override protected void onPreExecute() { mCallback = new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> futureManager) { // Unless the account creation was cancelled, try logging in again // after the account has been created. Log.i("ToFlux", "sent to flux"); } }; }
/** * Makes a GET request and parses the received JSON string as a Map. */ public static Map getJson(OIDCAccountManager accountManager, String url, Account account, AccountManagerCallback<Bundle> callback) throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException { String jsonString = makeRequest(accountManager, HttpRequest.METHOD_GET, url, account, callback); Log.i("APIUtility", jsonString); return new Gson().fromJson(jsonString, Map.class); }
public static List<JSONObject> getJsonList(OIDCAccountManager accountManager, String url, Account account, AccountManagerCallback<Bundle> callback) throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException { String jsonString = makeRequest(accountManager, HttpRequest.METHOD_GET, url, account, callback); Log.i("APIUtility", jsonString); return new Gson().fromJson(jsonString, List.class); }
/** * Makes an arbitrary HTTP request using the provided account. * * If the request doesn't execute successfully on the first try, the tokens will be refreshed * and the request will be retried. If the second try fails, an exception will be raised. */ public static String makeRequest(OIDCAccountManager accountManager, String method, String url, Account account, AccountManagerCallback<Bundle> callback) throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException { return makeRequest(accountManager, method, url, "", account, true, callback); }
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, String body, Account account, boolean doRetry, AccountManagerCallback<Bundle> callback) throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException { String accessToken = accountManager.getAccessToken(account, callback); String cookies = accountManager.getCookies(account, callback); // Prepare an API request using the accessToken HttpRequest request = new HttpRequest(url, method); request = prepareApiRequest(request, accessToken, cookies); if (body != "") { request.send(body); } if (request.ok()) { return request.body(); } else { int code = request.code(); String requestContent = "empty body"; try { requestContent = request.body(); } catch (HttpRequest.HttpRequestException e) { //Nothing to do, the response has no body or couldn't fetch it e.printStackTrace(); } if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN || (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) { // We're being denied access on the first try, let's renew the token and retry accountManager.invalidateAuthTokens(account); return makeRequest(accountManager, method, url, body, account, false, callback); } else { // An unrecoverable error or the renewed token didn't work either throw new IOException(request.code() + " " + request.message() + " " + requestContent); } } }
private void finishLogin(Intent intent) { String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String accountPassword = intent.getStringExtra(AccountManager.KEY_PASSWORD); String token = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN); final Account account = new Account(accountName, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE)); String accountType = Aptoide.getConfiguration().getAccountType(); String authTokenType = AptoideConfiguration.AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS; final Activity activity = getActivity(); AccountManager.get(getActivity()).addAccount(accountType, authTokenType, new String[]{"timelineLogin"}, intent.getExtras(), getActivity(), new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { if (activity != null) { activity.startService(new Intent(activity, RabbitMqService.class)); } ContentResolver.setSyncAutomatically(account, Aptoide.getConfiguration().getUpdatesSyncAdapterAuthority(), true); ContentResolver.addPeriodicSync(account, Aptoide.getConfiguration().getUpdatesSyncAdapterAuthority(), new Bundle(), 43200); ContentResolver.setSyncAutomatically(account, Aptoide.getConfiguration(). getAutoUpdatesSyncAdapterAuthority(), true); callback = (SignInCallback) getParentFragment(); if (callback != null) callback.loginEnded(); } }, new Handler(Looper.getMainLooper())); }
@Override protected void onPostExecute(final HttpUtil response) { if (response != null) { if (response.code() == 200) { Gson gson = new Gson(); User user = gson.fromJson(response.body().string(), User.class); Util.setUser(user); } else if (response.code() == 204) { Util.logout(MainActivity.this, new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> future) { new AlertDialog.Builder(MainActivity.this) .setTitle("Logout") .setMessage("Your account has been deleted") .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(MainActivity.this, WelcomeActivity.class)); finish(); } }) .show(); } }); } } else { Toast.makeText(MainActivity.this, "Can't reach server", Toast.LENGTH_LONG).show(); } refreshNavView(); // in All cases }
@OnClick(R.id.bt_logout) public void onLoggingOut() { am.removeAccount(Sessions.getAccount(am), new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> future) { logout(); } }, null); }
/** * Makes a GET request and parses the received JSON string as a Map. */ public static Map getJson(OIDCAccountManager accountManager, String url, Account account, AccountManagerCallback<Bundle> callback) throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException { String jsonString = makeRequest(accountManager, HttpRequest.METHOD_GET, url, account, callback); return new Gson().fromJson(jsonString, Map.class); }
/** * Makes an arbitrary HTTP request using the provided account. * * If the request doesn't execute successfully on the first try, the tokens will be refreshed * and the request will be retried. If the second try fails, an exception will be raised. */ public static String makeRequest(OIDCAccountManager accountManager, String method, String url, Account account, AccountManagerCallback<Bundle> callback) throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException { return makeRequest(accountManager, method, url, account, true, callback); }
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, Account account, boolean doRetry, AccountManagerCallback<Bundle> callback) throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException { String accessToken = accountManager.getAccessToken(account, callback); // Prepare an API request using the accessToken HttpRequest request = new HttpRequest(url, method); request = prepareApiRequest(request, accessToken); if (request.ok()) { return request.body(); } else { int code = request.code(); String requestContent = "empty body"; try { requestContent = request.body(); } catch (HttpRequest.HttpRequestException e) { //Nothing to do, the response has no body or couldn't fetch it e.printStackTrace(); } if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN || (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) { // We're being denied access on the first try, let's renew the token and retry accountManager.invalidateAuthTokens(account); return makeRequest(accountManager, method, url, account, false, callback); } else { // An unrecoverable error or the renewed token didn't work either throw new IOException(request.code() + " " + request.message() + " " + requestContent); } } }
/** * Get the stored data from a secure store, decrypting the data if needed. * @return The data store on the secure storage. */ public String retrieveStringData(AccountManager accountManager, Account account, String tokenType, AccountManagerCallback<Bundle> callback) throws UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException, IOException { String data = null; // Try retrieving an access token from the account manager. The boolean #SHOW_NOTIF_ON_AUTHFAILURE in the invocation // tells Android to show a notification if the token can't be retrieved. When the // notification is selected, it will launch the intent for re-authorisation. You could // launch it automatically here if you wanted to by grabbing the intent from the bundle. AccountManagerFuture<Bundle> futureManager; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { //noinspection deprecation futureManager = accountManager.getAuthToken( account, tokenType, SHOW_NOTIF_ON_AUTHFAILURE, callback, null); } else { futureManager = accountManager.getAuthToken( account, tokenType, null, SHOW_NOTIF_ON_AUTHFAILURE, callback, null); } String encryptedToken = futureManager.getResult().getString(AccountManager.KEY_AUTHTOKEN); if (encryptedToken != null) { data = dataEncUtils.decrypt(encryptedToken); } return data; }
private void addAccount() { String str = AccountHandler.getAccountTypes()[0]; AccountManager.get(this).addAccount(str, "androidmarket", null, createAddAccountOptions(this), null, new AccountManagerCallback() { public final void run(AccountManagerFuture<Bundle> paramAnonymousAccountManagerFuture) { try { Intent localIntent = (Intent)((Bundle)paramAnonymousAccountManagerFuture.getResult()).getParcelable("intent"); AuthenticatedActivity.this.startActivityForResult(localIntent, 21); AuthenticatedActivity.access$802$212b92e1(AuthenticatedActivity.this); return; } catch (OperationCanceledException localOperationCanceledException) { FinskyLog.d("Account add canceled. Finishing.", new Object[0]); AuthenticatedActivity.this.finish(); return; } catch (IOException localIOException) { FinskyLog.d("IOException while adding account: %s. Finishing.", new Object[] { localIOException }); AuthenticatedActivity.this.finish(); return; } catch (AuthenticatorException localAuthenticatorException) { FinskyLog.d("AuthenticatorException while adding account: %s. Finishing.", new Object[] { localAuthenticatorException }); AuthenticatedActivity.this.finish(); } } }, null); }
public final void confirmCredentials(String paramString1, String paramString2) { Account localAccount = AccountHandler.findAccount(paramString1, FinskyApp.get()); AccountManager localAccountManager = AccountManager.get(FinskyApp.get()); Bundle localBundle = new Bundle(); localBundle.putString("password", paramString2); localAccountManager.confirmCredentials(localAccount, localBundle, getActivity(), new AccountManagerCallback() { public final void run(AccountManagerFuture<Bundle> paramAnonymousAccountManagerFuture) { try { if (((Bundle)paramAnonymousAccountManagerFuture.getResult()).getBoolean("booleanResult")) { AuthChallengeSidecar.this.succeed(); return; } AuthChallengeSidecar.this.fail(); return; } catch (OperationCanceledException localOperationCanceledException) { FinskyLog.w("OperationCanceledException: %s", new Object[] { localOperationCanceledException }); AuthChallengeSidecar.this.fail(); return; } catch (IOException localIOException) { FinskyLog.w("IOException: %s", new Object[] { localIOException }); AuthChallengeSidecar.this.fail(); return; } catch (AuthenticatorException localAuthenticatorException) { FinskyLog.w("AuthenticatorException: %s", new Object[] { localAuthenticatorException }); AuthChallengeSidecar.this.fail(); } } }, null); }
public void initAccountCreateIfNeeded() { Account[] accounts = accountManager.getAccountsByType(AccountGeneral.ACCOUNT_TYPE); if(accounts.length == 0) { accountManager.addAccount(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, null, null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { future.getResult(); // Used to catch exceptions restartActivity(); } catch (OperationCanceledException | IOException | AuthenticatorException e) { finish(); } } }, null); } else { Account selectedAccount = accounts[0]; String lastAccount = getLastAccount(); if(lastAccount != null) { UnicapApplication.log(lastAccount); for (Account account : accounts) { if(account.name.equals(lastAccount)) { selectedAccount = account; } } } selectAccount(selectedAccount); } }
public void remove(final String email, AccountManagerCallback<Boolean> callback) { final Account account = getAccountByEmail(email); String isDefaultString = mAccountManager.getUserData(account, KEY_IS_DEFAULT); //If removing default user, clear the static user object if(isDefaultString.equals(TRUE)) { AppData.defaultUser = null; } mAccountManager.removeAccount(account, callback, null); }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CHOOSE_ACCOUNT_IDTOKEN_REQUEST || requestCode == CHOOSE_ACCOUNT_ACCESSTOKEN_REQUEST || requestCode == CHOOSE_ACCOUNT_REFRESHTOKEN_REQUEST) { if (resultCode == RESULT_OK) { String tokeType = GetTokenType(requestCode); String accountName= data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); String accountType = data.getExtras().getString(AccountManager.KEY_ACCOUNT_TYPE); Account account = new Account(accountName, accountType); AccountManager accountManager = AccountManager.get(this); accountManager.getAuthToken(account, tokeType, null, false, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bundle = future.getResult(); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(bundle.getString("authAccount")) .setMessage(bundle.getString("authtoken")) .show(); } catch(Exception ex) { ex.getMessage(); } } }, null); } } }
@Override public AccountManagerFuture<Bundle> getAuthTokenAndCheck(AccountManagerCallback<Bundle> cb) { return super.getAuthTokenAndCheck(new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { getUserInfoWithWaitDialog(); } }); }
@Override public AccountManagerFuture<Bundle> getAuthTokenAndCheck(final AccountManagerCallback<Bundle> cb) { return getAuthToken(new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { if (!future.isCancelled()) { if (cb != null) { cb.run(future); } } } }); }