当前位置: 首页>>代码示例>>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;未经允许,请勿转载。