예제 #1
0
  @Override
  public Bundle addAccount(
      AccountAuthenticatorResponse response,
      String accountType,
      String authTokenType,
      String[] requiredFeatures,
      Bundle options) {
    Log.i(TAG, "addAccount()");
    AccountManager am = AccountManager.get(mContext);
    Account[] accounts = am.getAccountsByType(accountType);
    if (accounts.length > 0) {
      int errCode = AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION;
      Log.w(TAG, errAccountExists);

      // too bad this doesn't show the user an error or message of any kind
      final Bundle errBundle = new Bundle();
      errBundle.putInt(AccountManager.KEY_ERROR_CODE, errCode);
      errBundle.putString(AccountManager.KEY_ERROR_MESSAGE, errAccountExists);
      accountExistsHandler.sendEmptyMessage(0);

      // choose to return as response.onError over bundle
      response.onError(errCode, errAccountExists);
      return null;
    }

    final Intent intent = new Intent(mContext, LDAPAuthenticatorActivity.class);
    intent.putExtra(LDAPAuthenticatorActivity.PARAM_AUTHTOKEN_TYPE, authTokenType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);

    // choose to return as bundle over response.onResult
    return bundle;
  }
 /** Sends the result or a Constants.ERROR_CODE_CANCELED error if a result isn't present. */
 public void finish() {
   if (mAccountAuthenticatorResponse != null) {
     // send the result bundle back if set, otherwise send an error.
     if (mResultBundle != null) {
       mAccountAuthenticatorResponse.onResult(mResultBundle);
     } else {
       mAccountAuthenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, "canceled");
     }
     mAccountAuthenticatorResponse = null;
   }
   super.finish();
 }