當前位置: 首頁>>代碼示例>>Java>>正文


Java AccountManagerCallback類代碼示例

本文整理匯總了Java中android.accounts.AccountManagerCallback的典型用法代碼示例。如果您正苦於以下問題:Java AccountManagerCallback類的具體用法?Java AccountManagerCallback怎麽用?Java AccountManagerCallback使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AccountManagerCallback類屬於android.accounts包,在下文中一共展示了AccountManagerCallback類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addAccount

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:31,代碼來源:VAccountManager.java

示例2: removeAccount

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
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);
}
 
開發者ID:Aptoide,項目名稱:aptoide-client,代碼行數:17,代碼來源:MyAccountActivity.java

示例3: addAccount

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
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);
}
 
開發者ID:Aptoide,項目名稱:aptoide-client,代碼行數:19,代碼來源:MyAccountActivity.java

示例4: addNewAccount

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
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);
}
 
開發者ID:EnlightNS,項目名稱:enlightns-android,代碼行數:21,代碼來源:RecordListing.java

示例5: getAccessToken

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
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);
}
 
開發者ID:digigene,項目名稱:account-authenticator,代碼行數:26,代碼來源:AuthenticatorManager.java

示例6: fetchPioneerAccount

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
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);
}
 
開發者ID:baoti,項目名稱:Pioneer,代碼行數:24,代碼來源:MainPresenter.java

示例7: logout

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
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);
        }
    }
 
開發者ID:gabrielduque,項目名稱:unicap,代碼行數:21,代碼來源:MainActivity.java

示例8: removeAccount

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:AndrewJack,項目名稱:moment-for-android-wear,代碼行數:21,代碼來源:UserManager.java

示例9: getToken

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
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;
        }
    }
 
開發者ID:dgrahn,項目名稱:csci578,代碼行數:22,代碼來源:AuthenticationManager.java

示例10: getAuthToken

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
@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);
            }
        });
    }
}
 
開發者ID:tech-team,項目名稱:decider-android,代碼行數:18,代碼來源:ToolbarActivity.java

示例11: logout

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
/**
 * 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()));
}
 
開發者ID:shiftconnects,項目名稱:android-auth-manager,代碼行數:30,代碼來源:AuthenticationManager.java

示例12: addNewAccount

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
/**
 * 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());
            }
        }
    });
}
 
開發者ID:pimatic,項目名稱:pimatic-android,代碼行數:20,代碼來源:AccountsActivity.java

示例13: attemptLogout

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:gengkev,項目名稱:thyroxine,代碼行數:32,代碼來源:IodineAuthUtils.java

示例14: queryGmailLabels

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
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 */);
}
 
開發者ID:godstale,項目名稱:retrowatch,代碼行數:23,代碼來源:ContentManager.java

示例15: getToken

import android.accounts.AccountManagerCallback; //導入依賴的package包/類
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());
}
 
開發者ID:bdkoepke,項目名稱:SmackPlus,代碼行數:25,代碼來源:SmackPlusSetup.java


注:本文中的android.accounts.AccountManagerCallback類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。