Example usage for android.accounts AccountManager getPassword

List of usage examples for android.accounts AccountManager getPassword

Introduction

In this page you can find the example usage for android.accounts AccountManager getPassword.

Prototype

public String getPassword(final Account account) 

Source Link

Document

Gets the saved password associated with the account.

Usage

From source file:com.rowland.hashtrace.sync.TweetHashTracerSyncAdapter.java

/**
 * Helper method to get the fake account to be used with SyncAdapter, or
 * make a new one if the fake account doesn't exist yet. If we make a new
 * account, we call the onAccountCreated method so we can initialize things.
 *
 * @param context The context used to access the account service
 * @return a fake account.//w w  w  .j a v a 2  s  .  c  o m
 */
public static Account getSyncAccount(Context context) {
    // Get an instance of the Android account manager
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.sync_account_type));

    // If the password doesn't exist, the account doesn't exist
    if (null == accountManager.getPassword(newAccount)) {

        /*
         * Add the account and account type, no password or user data If
         * successful, return the Account object, otherwise report an error.
         */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in in your <provider>
         * element in the manifest, then call
         * ContentResolver.setIsSyncable(account, AUTHORITY, 1) here.
         */

        onAccountCreated(newAccount, context);
    }

    return newAccount;
}

From source file:co.carlosjimenez.android.currencyalerts.app.sync.ForexSyncAdapter.java

/**
 * Helper method to get the fake account to be used with SyncAdapter, or make a new one
 * if the fake account doesn't exist yet.  If we make a new account, we call the
 * onAccountCreated method so we can initialize things.
 *
 * @param context The context used to access the account service
 * @return a fake account.//  w  w w .ja v  a2 s.  c  om
 */
public static Account getSyncAccount(Context context) {
    // Get an instance of the Android account manager
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.sync_account_type));

    // If the password doesn't exist, the account doesn't exist
    if (null == accountManager.getPassword(newAccount)) {

        /*
         * Add the account and account type, no password or user data
         * If successful, return the Account object, otherwise report an error.
         */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */

        onAccountCreated(newAccount, context);
    }
    return newAccount;
}

From source file:com.alphabetbloc.accessmrs.utilities.NetworkUtils.java

private static void getServerCredentials() {
    final AccountManager am = AccountManager.get(App.getApp());
    Account[] accounts = am.getAccountsByType(App.getApp().getString(R.string.app_account_type));

    if (App.DEBUG)
        Log.v(TAG, "accounts.length =" + accounts.length);
    if (accounts.length <= 0) {
        if (App.DEBUG)
            Log.v(TAG, "no accounts have been set up");

    } else {//from  ww  w .  j  av a2s  .  com

        mUsername = accounts[0].name;
        String encPwd = am.getPassword(accounts[0]);
        mPassword = EncryptionUtil.decryptString(encPwd);
    }

}

From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java

/**
 * Helper method to get the fake account to be used with SyncAdapter, or make a new one
 * if the fake account doesn't exist yet.  If we make a new account, we call the
 * onAccountCreated method so we can initialize things.
 *
 * @param context The context used to access the account service
 * @return a fake account.//from   w  w  w .  j a  va2s . co  m
 */
private static Account getSyncAccount(Context context) {
    // Get an instance of the Android account manager
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.sync_account_type));

    // If the password doesn't exist, the account doesn't exist
    if (null == accountManager.getPassword(newAccount)) {

        /*
         * Add the account and account type, no password or user data
         * If successful, return the Account object, otherwise report an error.
         */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */

        onAccountCreated(newAccount, context);

    }
    return newAccount;
}

From source file:com.upenn.chriswang1990.sunshine.sync.SunshineSyncAdapter.java

/**
 * Helper method to get the fake account to be used with SyncAdapter, or make a new one
 * if the fake account doesn't exist yet.  If we make a new account, we call the
 * onAccountCreated method so we can initialize things.
 *
 * @param context The context used to access the account service
 * @return a fake account./*from  w w  w.j a  v a 2  s.  c om*/
 */
public static Account getSyncAccount(Context context) {
    // Get an instance of the Android account manager
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.sync_account_type));
    // If the password doesn't exist, the account doesn't exist
    if (null == accountManager.getPassword(newAccount)) {

        /*
         * Add the account and account type, no password or user data
         * If successful, return the Account object, otherwise report an error.
         */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */
        onAccountCreated(newAccount, context);
    }
    return newAccount;
}

From source file:io.github.hidroh.materialistic.AppUtils.java

@SuppressLint("MissingPermission")
public static Pair<String, String> getCredentials(Context context) {
    String username = Preferences.getUsername(context);
    if (TextUtils.isEmpty(username)) {
        return null;
    }/*from www .  j ava  2  s .co  m*/
    AccountManager accountManager = AccountManager.get(context);
    Account[] accounts = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID);
    for (Account account : accounts) {
        if (TextUtils.equals(username, account.name)) {
            return Pair.create(username, accountManager.getPassword(account));
        }
    }
    return null;
}

From source file:com.jackie.sunshine.app.sync.SunshineSyncAdapter.java

/**
 * Helper method to get the fake account to be used with SyncAdapter, or make a new one
 * if the fake account doesn't exist yet.  If we make a new account, we call the
 * onAccountCreated method so we can initialize things.
 *
 * @param context The context used to access the account service
 * @return a fake account.//www . j ava 2 s.co  m
 */
public static Account getSyncAccount(Context context) {
    // Get an instance of the Android account manager
    AccountManager manager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    // Create the account type and default account
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.sync_account_type));

    // If the password doesn't exist, the account doesn't exist
    if (manager.getPassword(newAccount) == null) {
        /*
         * Add the account and account type, no password or user data
         * If successful, return the Account object, otherwise report an error.
         */
        if (!manager.addAccountExplicitly(newAccount, "", null))
            return null;

        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */
        onAccountCreated(newAccount, context);
    }

    return newAccount;
}

From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java

/**
 * Gets the fictitious account to be used with the sync adapter, or makes a new one
 * if the fictitious account doesn't exist yet.  If we make a new account, we call the
 * onAccountCreated method so we can initialize things.
 *///from   w  w  w.  j a  va2s .co m
public static Account getSyncAccount(Context context) {
    // Get an instance of the android account manager.
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account.
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.sync_account_type));

    // If the password doesn't exist, the account doesn't exist. Add the account.
    if (null == accountManager.getPassword(newAccount)) {
        // Add the account and account type, no password or user data.
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }

        onAccountCreated(newAccount, context);
    }
    return newAccount;
}

From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java

/**
 * Helper method to get the fake account to be used with SyncAdapter, or make a new one
 * if the fake account doesn't exist yet.  If we make a new account, we call the
 * onAccountCreated method so we can initialize things.
 *
 * @param context The context used to access the account service
 * @return a fake account.//from  www  . jav  a  2 s  .c  o m
 */
public static Account getSyncAccount(Context context) {
    //Log.d("Weather4USyncAdapter", "getSyncAccount");
    // Get an instance of the Android account manager
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.sync_account_type));

    // If the password doesn't exist, the account doesn't exist
    if (null == accountManager.getPassword(newAccount)) {

        /*
         * Add the account and account type, no password or user data
         * If successful, return the Account object, otherwise report an error.
         */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */

        onAccountCreated(newAccount, context);
    }
    return newAccount;
}

From source file:org.klnusbaum.udj.auth.Authenticator.java

@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,
        Bundle loginOptions) {//w  w  w.  j a  v a  2s. c  o  m
    final AccountManager am = AccountManager.get(context);
    final String password = am.getPassword(account);
    if (password != null) {
        try {
            final ServerConnection.AuthResult authResult = ServerConnection.authenticate(account.name,
                    password);
            if (!TextUtils.isEmpty(authResult.ticketHash)) {
                am.setUserData(account, Constants.USER_ID_DATA, authResult.userId);
                return bundleUpAuthToken(account, authResult.ticketHash);
            }
        } catch (AuthenticationException e) {
            //TODO actually do something with this exception 
        } catch (IOException e) {
            //TODO actually do something with this exception 
        } catch (JSONException e) {
            //TODO actually do something with this exception 
        } catch (APIVersionException e) {
            final Intent intent = new Intent(context, NeedUpdateActivity.class);
            intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
            intent.putExtra(AccountManager.KEY_ERROR_CODE, Constants.AUTH_API_VERSION_ERROR);
            final Bundle bundle = new Bundle();
            bundle.putParcelable(AccountManager.KEY_INTENT, intent);
            return bundle;
        }
    }

    //Oh snap, they're username and password didn't work. O well, better have
    // them sort it out.
    final Intent intent = new Intent(context, AuthActivity.class);
    intent.putExtra(AuthActivity.PARAM_USERNAME, account.name);
    intent.putExtra(AuthActivity.PARAM_AUTHTOKEN_TYPE, authTokenType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}