当前位置: 首页>>代码示例>>Java>>正文


Java AccountManager类代码示例

本文整理汇总了Java中android.accounts.AccountManager的典型用法代码示例。如果您正苦于以下问题:Java AccountManager类的具体用法?Java AccountManager怎么用?Java AccountManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AccountManager类属于android.accounts包,在下文中一共展示了AccountManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendResult

import android.accounts.AccountManager; //导入依赖的package包/类
public void sendResult() {
    IAccountManagerResponse response = getResponseAndClose();
    if (response != null) {
        try {
            Account[] accounts = new Account[mAccountsWithFeatures.size()];
            for (int i = 0; i < accounts.length; i++) {
                accounts[i] = mAccountsWithFeatures.get(i);
            }
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, getClass().getSimpleName() + " calling onResult() on response "
                        + response);
            }
            Bundle result = new Bundle();
            result.putParcelableArray(AccountManager.KEY_ACCOUNTS, accounts);
            response.onResult(result);
        } catch (RemoteException e) {
            // if the caller is dead then there is no one to care about remote exceptions
            Log.v(TAG, "failure while notifying response", e);
        }
    }
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:22,代码来源:VAccountManagerService.java

示例2: checkAccount

import android.accounts.AccountManager; //导入依赖的package包/类
public void checkAccount() {
    if (mCurrentAccount >= mAccountsOfType.length) {
        sendResult();
        return;
    }

    final IAccountAuthenticator accountAuthenticator = mAuthenticator;
    if (accountAuthenticator == null) {
        // It is possible that the authenticator has died, which is indicated by
        // mAuthenticator being set to null. If this happens then just abort.
        // There is no need to send back a result or error in this case since
        // that already happened when mAuthenticator was cleared.
        Log.v(TAG, "checkAccount: aborting session since we are no longer"
                + " connected to the authenticator, " + toDebugString());
        return;
    }
    try {
        accountAuthenticator.hasFeatures(this, mAccountsOfType[mCurrentAccount], mFeatures);
    } catch (RemoteException e) {
        onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "remote exception");
    }
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:23,代码来源:VAccountManagerService.java

示例3: getAuthToken

import android.accounts.AccountManager; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount,
            mAuthTokenType, mNotifyAuthFailure, null, null);
    Bundle result;
    try {
        result = future.getResult();
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
    String authToken = null;
    if (future.isDone() && !future.isCancelled()) {
        if (result.containsKey(AccountManager.KEY_INTENT)) {
            Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
            throw new AuthFailureError(intent);
        }
        authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
    }
    if (authToken == null) {
        throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
    }

    return authToken;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:AndroidAuthenticator.java

示例4: bind

import android.accounts.AccountManager; //导入依赖的package包/类
void bind() {
	Log.v(TAG, "initiating bind to authenticator type " + mAuthenticatorInfo.desc.type);
	Intent intent = new Intent();
	intent.setAction(AccountManager.ACTION_AUTHENTICATOR_INTENT);
	intent.setClassName(mAuthenticatorInfo.serviceInfo.packageName, mAuthenticatorInfo.serviceInfo.name);
	intent.putExtra("_VA_|_user_id_", mUserId);

	if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
		Log.d(TAG, "bind attempt failed for " + toDebugString());
		onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "bind failure");
	}
}
 
开发者ID:codehz,项目名称:container,代码行数:13,代码来源:VAccountManagerService.java

示例5: createAuthNotification

import android.accounts.AccountManager; //导入依赖的package包/类
private void createAuthNotification()
{
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(getContext(), AuthenticatorActivity.AUTH_NOTIFICATION_CHANNEL_ID)
                .setContentTitle(getContext().getString(R.string.sync_ntf_needs_reauthentication_title))
                .setContentText(getContext().getString(R.string.sync_ntf_needs_reauthentication_description))
                .setSmallIcon(R.mipmap.ic_launcher)
                .setAutoCancel(true);

    Intent intent = new Intent(getContext(), AuthenticatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, getContext().getString(R.string.account_type));
    intent.putExtra(AuthenticatorActivity.ARG_AUTH_TOKEN_TYPE, AuthenticatorActivity.ARG_AUTH_TOKEN_TYPE);
    intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, false);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());
    stackBuilder.addParentStack(AuthenticatorActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    NotificationManager ntfMgr =
            (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
    ntfMgr.notify(AuthenticatorActivity.AUTH_NOTIFICATION_ID, builder.build());
}
 
开发者ID:danvratil,项目名称:FBEventSync,代码行数:25,代码来源:CalendarSyncAdapter.java

示例6: checkAccount

import android.accounts.AccountManager; //导入依赖的package包/类
public void checkAccount() {
	if (mCurrentAccount >= mAccountsOfType.length) {
		sendResult();
		return;
	}

	final IAccountAuthenticator accountAuthenticator = mAuthenticator;
	if (accountAuthenticator == null) {
		// It is possible that the authenticator has died, which is indicated by
		// mAuthenticator being set to null. If this happens then just abort.
		// There is no need to send back a result or error in this case since
		// that already happened when mAuthenticator was cleared.
		Log.v(TAG, "checkAccount: aborting session since we are no longer"
                      + " connected to the authenticator, " + toDebugString());
		return;
	}
	try {
		accountAuthenticator.hasFeatures(this, mAccountsOfType[mCurrentAccount], mFeatures);
	} catch (RemoteException e) {
		onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "remote exception");
	}
}
 
开发者ID:codehz,项目名称:container,代码行数:23,代码来源:VAccountManagerService.java

示例7: getUsername

import android.accounts.AccountManager; //导入依赖的package包/类
public static String getUsername(Context c) {
    AccountManager manager = AccountManager.get(c);
    Account[] accounts = manager.getAccountsByType("com.google");
    List<String> possibleEmails = new LinkedList<String>();

    for (Account account : accounts) {
        // TODO: Check possibleEmail against an email regex or treat
        // account.name as an email address only for certain account.type values.
        possibleEmails.add(account.name);
    }

    if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) {
        String email = possibleEmails.get(0);
        String[] parts = email.split("@");

        if (parts.length > 1)
            return parts[0];
    }
    return null;
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:21,代码来源:Util.java

示例8: getName

import android.accounts.AccountManager; //导入依赖的package包/类
private String getName() {
    AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS)
            != PackageManager.PERMISSION_GRANTED) {
        return null;
    }

    Account[] list = manager.getAccounts();

    for (Account account : list) {
        if (account.type.equalsIgnoreCase("com.google")) {
            return account.name;
        }
    }
    return null;
}
 
开发者ID:hypertrack,项目名称:hypertrack-live-android,代码行数:17,代码来源:Profile.java

示例9: getUserEmail

import android.accounts.AccountManager; //导入依赖的package包/类
private ArrayList<String> getUserEmail(){

		ArrayList<String> email = new ArrayList<String>();

		Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
		Account[] accounts = AccountManager.get(VerifyOTP.this).getAccounts();
		for (Account account : accounts) {
			if (emailPattern.matcher(account.name).matches()) {
				String possibleEmail = account.name;
				if(possibleEmail != null)
					if(possibleEmail.length() !=0 ){
						email.add(possibleEmail);
					}
			}
		}		
		return email;

	}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:19,代码来源:VerifyOTP.java

示例10: sendResult

import android.accounts.AccountManager; //导入依赖的package包/类
public void sendResult() {
	IAccountManagerResponse response = getResponseAndClose();
	if (response != null) {
		try {
			Account[] accounts = new Account[mAccountsWithFeatures.size()];
			for (int i = 0; i < accounts.length; i++) {
				accounts[i] = mAccountsWithFeatures.get(i);
			}
			if (Log.isLoggable(TAG, Log.VERBOSE)) {
				Log.v(TAG, getClass().getSimpleName() + " calling onResult() on response "
						+ response);
			}
			Bundle result = new Bundle();
			result.putParcelableArray(AccountManager.KEY_ACCOUNTS, accounts);
			response.onResult(result);
		} catch (RemoteException e) {
			// if the caller is dead then there is no one to care about remote exceptions
			Log.v(TAG, "failure while notifying response", e);
		}
	}
}
 
开发者ID:codehz,项目名称:container,代码行数:22,代码来源:VAccountManagerService.java

示例11: init

import android.accounts.AccountManager; //导入依赖的package包/类
protected void init() {
    initCrypto();

    accountManager = AccountManager.get(getBaseContext());
    serverHandler = new AuthServerHandlerImpl();

    userName = (EditText) findViewById(R.id.user_name);
    password = (EditText) findViewById(R.id.password);
    signIn = (Button) findViewById(R.id.signin_button);
    progressLayout = findViewById(R.id.progress_layout);

    Intent intent = getIntent();
    authTokenType = getIntent().getStringExtra(GlobalConstant.AUTH_TYPE);
    if (authTokenType == null) {
        authTokenType = GlobalConstant.AUTHTOKEN_TYPE_FULL_ACCESS;
    }

    isNewAccount = intent.getBooleanExtra(GlobalConstant.IS_ADDING_NEW_ACCOUNT, true);
    if (!isNewAccount) {
        // existing account
        String accountName = getIntent().getStringExtra(GlobalConstant.ACCOUNT_NAME);
        userName.setText(accountName);
    }

    signIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            login();
        }
    });
}
 
开发者ID:6thsolution,项目名称:EasyAppleSyncAdapter,代码行数:32,代码来源:BaseLoginActivity.java

示例12: passDataToAuthenticator

import android.accounts.AccountManager; //导入依赖的package包/类
/**
 * Pass the data from server to authenticator class
 *
 * @param intent the intent contain data from user and server {@link AccountManager#KEY_ACCOUNT_NAME},
 *               {@link AccountManager#KEY_AUTHTOKEN}, {@link AccountManager#KEY_ACCOUNT_TYPE} and
 *               {@link GlobalConstant#PARAM_USER_PASS}
 * @throws NoSuchPaddingException
 * @throws InvalidAlgorithmParameterException
 * @throws NoSuchAlgorithmException
 * @throws IllegalBlockSizeException
 * @throws BadPaddingException
 * @throws InvalidKeyException
 * @throws UnsupportedEncodingException
 * @throws SignInException
 */
private void passDataToAuthenticator(Intent intent)
        throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException,
        IllegalBlockSizeException, BadPaddingException, InvalidKeyException, UnsupportedEncodingException,
        SignInException {

    if (intent.hasExtra(SIGNIN_ERROR)) throw new SignInException();

    String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
    String accountPassword = intent.getStringExtra(GlobalConstant.PARAM_USER_PASS);
    accountPassword = Crypto.armorEncrypt(accountPassword.getBytes("UTF-8"), this);

    final Account account = new Account(accountName, authTokenType);

    if (isNewAccount) {
        String iCalId = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN);
        String authtoken = intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);

        // encrypt user id and pass it to intent
        iCalId = Crypto.armorEncrypt(iCalId.getBytes("UTF-8"), this);
        intent.putExtra(AccountManager.KEY_AUTHTOKEN, iCalId);

        final Bundle extraData = new Bundle();
        extraData.putString(PARAM_PRINCIPAL, iCalId);

        accountManager.addAccountExplicitly(account, accountPassword, extraData);
        accountManager.setAuthToken(account, authtoken, iCalId);
    } else {
        accountManager.setPassword(account, accountPassword);
    }

    // encrypt password and pass it to intent
    intent.putExtra(GlobalConstant.PARAM_USER_PASS, accountPassword);


    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);
    finish();
}
 
开发者ID:6thsolution,项目名称:EasyAppleSyncAdapter,代码行数:54,代码来源:BaseLoginActivity.java

示例13: onCreate

import android.accounts.AccountManager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_activity);
    mAccountManager = AccountManager.get(getBaseContext());

    findViewById(R.id.submit)
            .setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            addAccount();
                        }
                    });
}
 
开发者ID:googlesamples,项目名称:account-transfer-api,代码行数:16,代码来源:AuthenticatorActivity.java

示例14: getResult

import android.accounts.AccountManager; //导入依赖的package包/类
@Override
public Bundle getResult() throws OperationCanceledException, IOException, AuthenticatorException {
	Bundle bundle = mFuture.getResult();
	String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
	String accountType = bundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
	if (isAccountAllowed(accountName, accountType, mUid))
		return bundle;
	else
		throw new OperationCanceledException("XPrivacy");
}
 
开发者ID:ukanth,项目名称:XPrivacy,代码行数:11,代码来源:XAccountManager.java

示例15: populateAccountTextView

import android.accounts.AccountManager; //导入依赖的package包/类
private void populateAccountTextView() {
    AccountManager am = AccountManager.get(this);
    Account[] accounts = am.getAccountsByType(ACCOUNT_TYPE);
    String accountString = "Accounts of type " + ACCOUNT_TYPE + " are : \n";
    if (accounts.length != 0) {
        for (Account account : accounts) {
            accountString += "Account:" +  account.name + "\n";
        }
    } else {
        accountString = "No Accounts of type " + ACCOUNT_TYPE +
                " found. Please add accounts before exporting.";
        mAccountTextView.setTextColor(Color.RED);
    }
    mAccountTextView.setText(accountString);
}
 
开发者ID:googlesamples,项目名称:account-transfer-api,代码行数:16,代码来源:MainActivity.java


注:本文中的android.accounts.AccountManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。