android.accounts.AccountManagerCallback Java Examples

The following examples show how to use android.accounts.AccountManagerCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentManager.java    From retrowatch with Apache License 2.0 6 votes vote down vote up
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 */);
}
 
Example #2
Source File: ContentManager.java    From retrowatch with Apache License 2.0 6 votes vote down vote up
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 */);
}
 
Example #3
Source File: MainPresenter.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: AuthenticationManager.java    From android-auth-manager with Apache License 2.0 6 votes vote down vote up
/**
 * 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()));
}
 
Example #5
Source File: MyAccountActivity.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #6
Source File: MyAccountActivity.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #7
Source File: MainPresenter.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #8
Source File: AuthUtils.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #9
Source File: SystemAccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType,
        Bundle options, Activity activity, AccountManagerCallback<Bundle> callback,
        Handler handler) {
    return mAccountManager.getAuthToken(account, authTokenType, options, activity, callback,
            handler);
}
 
Example #10
Source File: EvercamAccount.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
        AppData.evercamCameraList.clear();
    }

    mAccountManager.removeAccount(account, callback, null);
}
 
Example #11
Source File: AuthUtils.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #12
Source File: MainActivity.java    From cnode-android with MIT License 5 votes vote down vote up
private void signIn() {
    accountManager.addAccount(AccountAuthenticator.ACCOUNT_TYPE, null, null, null, this,
            new AccountManagerCallback<Bundle>() {
                @Override
                public void run(AccountManagerFuture<Bundle> future) {
                    Log.d(TAG, String.valueOf(future.isDone()));
                }
            }, null);
}
 
Example #13
Source File: c.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
c(AccountManager accountmanager, Activity activity, Handler handler, AccountManagerCallback accountmanagercallback, Account account, String s)
{
    a = accountmanager;
    f = account;
    g = s;
    super(accountmanager, activity, handler, accountmanagercallback);
}
 
Example #14
Source File: e.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public e(AccountManager accountmanager, Activity activity, Handler handler, AccountManagerCallback accountmanagercallback)
{
    e = accountmanager;
    super(new f(accountmanager));
    b = handler;
    c = accountmanagercallback;
    d = activity;
}
 
Example #15
Source File: a.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
a(AccountManager accountmanager, Activity activity, Handler handler, AccountManagerCallback accountmanagercallback, Account account, String s)
{
    a = accountmanager;
    f = account;
    g = s;
    super(accountmanager, activity, handler, accountmanagercallback);
}
 
Example #16
Source File: AuthUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #17
Source File: PredatorAccount.java    From Capstone-Project with MIT License 5 votes vote down vote up
/**
 * Get a authentication token if available, otherwise add a new account and then get a new
 * authentication token.
 *
 * @param activity      Current activity
 * @param accountType   Name of the account
 * @param authTokenType Type of the authentication token
 * @return An string observable which will provide auth token
 */
public static Observable<String> getAuthToken(final Activity activity,
                                              final String accountType,
                                              final String authTokenType) {
    return Observable.create(new ObservableOnSubscribe<String>() {
        @Override
        public void subscribe(final ObservableEmitter<String> emitter) throws Exception {
            AccountManager accountManager = AccountManager.get(activity.getApplicationContext());
            accountManager.getAuthTokenByFeatures(accountType,
                    authTokenType,
                    null,
                    activity,
                    null,
                    null,
                    new AccountManagerCallback<Bundle>() {
                        @Override
                        public void run(AccountManagerFuture<Bundle> future) {
                            Bundle bundle;
                            try {
                                if (future.isCancelled()) {
                                    emitter.onError(new RuntimeException("Auth request was cancelled"));
                                } else if (future.isDone()) {
                                    bundle = future.getResult();
                                    final String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
                                    emitter.onNext(authToken);
                                    emitter.onComplete();
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                emitter.onError(e);
                            }
                        }
                    },
                    null);
        }
    });
}
 
Example #18
Source File: AccountSensitiveDataStorageUtils.java    From android-java-connect-rest-sample with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: AccountManagerCompat.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
public static AccountManagerFuture<Bundle> getAuthToken(AccountManager manager,
                                                        Account account, String authTokenType,
                                                        Bundle options,
                                                        boolean notifyAuthFailure,
                                                        AccountManagerCallback<Bundle> callback,
                                                        Handler handler) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        return manager.getAuthToken(account, authTokenType, options, notifyAuthFailure,
                callback, handler);
    } else {
        //noinspection deprecation
        return manager.getAuthToken(account, authTokenType, notifyAuthFailure, callback,
                handler);
    }
}
 
Example #20
Source File: FragmentSignIn.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
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()));


    }
 
Example #21
Source File: SystemAccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType,
        Bundle options, Activity activity, AccountManagerCallback<Bundle> callback,
        Handler handler) {
    return mAccountManager.getAuthToken(account, authTokenType, options, activity, callback,
            handler);
}
 
Example #22
Source File: SystemAccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public AccountManagerFuture<Bundle> confirmCredentials(Account account, Bundle bundle,
        Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
    return mAccountManager.confirmCredentials(account, bundle, activity, callback, handler);
}
 
Example #23
Source File: AccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
AccountManagerFuture<Bundle> confirmCredentials(Account account, Bundle bundle,
Activity activity, AccountManagerCallback<Bundle> callback, Handler handler);
 
Example #24
Source File: SystemAccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public AccountManagerFuture<Boolean> removeAccount(Account account,
        AccountManagerCallback<Boolean> callback, Handler handler) {
    return mAccountManager.removeAccount(account, callback, handler);
}
 
Example #25
Source File: AccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
AccountManagerFuture<Boolean> removeAccount(Account account,
AccountManagerCallback<Boolean> callback, Handler handler);
 
Example #26
Source File: AccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType, Bundle options,
Activity activity, AccountManagerCallback<Bundle> callback, Handler handler);
 
Example #27
Source File: AccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType,
boolean notifyAuthFailure, AccountManagerCallback<Bundle> callback, Handler handler);
 
Example #28
Source File: SystemAccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public AccountManagerFuture<Bundle> confirmCredentials(Account account, Bundle bundle,
        Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
    return mAccountManager.confirmCredentials(account, bundle, activity, callback, handler);
}
 
Example #29
Source File: SystemAccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public AccountManagerFuture<Boolean> removeAccount(Account account,
        AccountManagerCallback<Boolean> callback, Handler handler) {
    return mAccountManager.removeAccount(account, callback, handler);
}
 
Example #30
Source File: AccountManagerDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType,
boolean notifyAuthFailure, AccountManagerCallback<Bundle> callback, Handler handler);