Example usage for android.accounts AccountManager get

List of usage examples for android.accounts AccountManager get

Introduction

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

Prototype

public static AccountManager get(Context context) 

Source Link

Document

Gets an AccountManager instance associated with a Context.

Usage

From source file:org.klnusbaum.udj.network.PlayerCommService.java

@Override
public void onHandleIntent(Intent intent) {
    Log.d(TAG, "In Player Comm Service");
    AccountManager am = AccountManager.get(this);
    final Account account = (Account) intent.getParcelableExtra(Constants.ACCOUNT_EXTRA);
    if (intent.getAction().equals(Intent.ACTION_INSERT)) {
        joinPlayer(intent, am, account, true);
    } else {//from w  ww.  j  a v  a2 s . c o  m
        Log.d(TAG, "Unrecognized action of, it was " + intent.getAction());
    }
}

From source file:de.syncdroid.service.SyncAdapter.java

public SyncAdapter(Context context, boolean autoInitialize, ProfileService profileService,
        LocationService locationService) {
    super(context, autoInitialize);
    mContext = context;//from  www.  j  av  a  2s  . c om
    this.profileService = profileService;
    this.locationService = locationService;
    mAccountManager = AccountManager.get(context);
}

From source file:com.androidquery.auth.GoogleHandle.java

public GoogleHandle(Activity act, String type, String email) {

    if (AQuery.ACTIVE_ACCOUNT.equals(email)) {
        email = getActiveAccount(act);/*  ww w  .  ja v  a 2 s. co m*/
    }

    this.act = act;
    this.type = type.substring(2);
    this.email = email;
    this.am = AccountManager.get(act);

}

From source file:com.piusvelte.cloudset.android.AccountsFragment.java

private void getAccountNames() {
    adapter.clear();//w w  w.  j  a v a 2  s .co  m
    AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext());
    Account[] accounts = accountManager.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);

    String[] names = new String[accounts.length];
    for (int i = 0; i < names.length; i++) {
        adapter.add(accounts[i].name);
    }

    adapter.notifyDataSetChanged();
}

From source file:com.manning.androidhacks.hack023.BootstrapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bootstrap);// ww w . ja  v  a  2 s .  c  o m

    mAccountManager = AccountManager.get(this);
    Account[] accounts = mAccountManager.getAccountsByType(AuthenticatorActivity.PARAM_ACCOUNT_TYPE);

    if (accounts.length == 0) {
        // There are no androidHacks accounts! We need to create one.
        Log.d(TAG, "No accounts found. Starting login...");
        final Intent intent = new Intent(this, AuthenticatorActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        startActivityForResult(intent, NEW_ACCOUNT);
    } else {
        // For now we assume that there's only one account.
        String password = mAccountManager.getPassword(accounts[0]);
        Log.d(TAG, "Using account with name " + accounts[0].name);
        if (password == null) {
            Log.d(TAG, "The password is empty, launching login");
            final Intent intent = new Intent(this, AuthenticatorActivity.class);
            intent.putExtra(AuthenticatorActivity.PARAM_USER, accounts[0].name);
            startActivityForResult(intent, EXISTING_ACCOUNT);
        } else {
            Log.d(TAG, "User and password found, no need for manual login");
            // The user is already logged in. Go ahead!
            startActivity(new Intent(this, MainActivity.class));
            finish();
        }
    }
}

From source file:com.ntsync.android.sync.activities.AccountStatisticListLoader.java

public AccountStatisticListLoader(Context context) {
    super(context);
    accountManager = AccountManager.get(context);
}

From source file:org.klnusbaum.udj.network.EventCommService.java

@Override
public void onHandleIntent(Intent intent) {
    Log.d(TAG, "In Event Comm Service");
    AccountManager am = AccountManager.get(this);
    final Account account = (Account) intent.getParcelableExtra(Constants.ACCOUNT_EXTRA);
    if (intent.getAction().equals(Intent.ACTION_INSERT)) {
        enterEvent(intent, am, account, true);
    } else if (intent.getAction().equals(Intent.ACTION_DELETE)) {
        //TODO handle if userId is null shouldn't ever be, but hey...
        leaveEvent(am, account, true);/*from www. j  a va  2 s  .  c o  m*/
    } else {
        Log.d(TAG, "ACTION wasn't delete or insert, it was " + intent.getAction());
    }
}

From source file:com.cerema.cloud2.operations.UpdateOCVersionOperation.java

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    AccountManager accountMngr = AccountManager.get(mContext);
    String statUrl = accountMngr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
    statUrl += AccountUtils.STATUS_PATH;
    RemoteOperationResult result = null;
    GetMethod get = null;/*  w  ww  . j  a v a2s  . c o m*/
    try {
        get = new GetMethod(statUrl);
        int status = client.executeMethod(get);
        if (status != HttpStatus.SC_OK) {
            client.exhaustResponse(get.getResponseBodyAsStream());
            result = new RemoteOperationResult(false, status, get.getResponseHeaders());

        } else {
            String response = get.getResponseBodyAsString();
            if (response != null) {
                JSONObject json = new JSONObject(response);
                if (json != null && json.getString("version") != null) {

                    String version = json.getString("version");
                    mOwnCloudVersion = new OwnCloudVersion(version);
                    if (mOwnCloudVersion.isVersionValid()) {
                        accountMngr.setUserData(mAccount, Constants.KEY_OC_VERSION,
                                mOwnCloudVersion.getVersion());
                        Log_OC.d(TAG, "Got new OC version " + mOwnCloudVersion.toString());

                        result = new RemoteOperationResult(ResultCode.OK);

                    } else {
                        Log_OC.w(TAG,
                                "Invalid version number received from server: " + json.getString("version"));
                        result = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION);
                    }
                }
            }
            if (result == null) {
                result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
            }
        }
        Log_OC.i(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": "
                + result.getLogMessage());

    } catch (JSONException e) {
        result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
        Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": "
                + result.getLogMessage(), e);

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": "
                + result.getLogMessage(), e);

    } finally {
        if (get != null)
            get.releaseConnection();
    }
    return result;
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrBillTask.java

protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException {

    AccountManager accountManager = AccountManager.get(context);
    android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google");

    String accountName = MyPreferences.getFlowzrAccount(context);
    if (accountName == null) {
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        Builder mNotifyBuilder = new NotificationCompat.Builder(context);
        mNotifyBuilder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon)
                .setWhen(System.currentTimeMillis()).setAutoCancel(true)
                .setContentTitle(context.getString(R.string.flowzr_sync))
                .setContentText(context.getString(R.string.flowzr_choose_account));
        nm.notify(0, mNotifyBuilder.build());
        Log.i("Flowzr", "account name is null");
        throw new ImportExportException(R.string.flowzr_choose_account);
    }/* ww w  .j av a2  s  . co m*/
    Account useCredential = null;
    for (int i = 0; i < accounts.length; i++) {
        if (accountName.equals(((android.accounts.Account) accounts[i]).name)) {
            useCredential = accounts[i];
        }
    }
    AccountManager.get(context).getAuthToken(useCredential, "ah", null, (Activity) context,
            new GetAuthTokenCallback(), null);

    return null;
}