Example usage for android.accounts Account Account

List of usage examples for android.accounts Account Account

Introduction

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

Prototype

public Account(@NonNull Account other, @NonNull String accessId) 

Source Link

Usage

From source file:com.clearcenter.mobile_demo.mdStatusActivity.java

public void resetData() {
    int count = getContentResolver().delete(mdDeviceSamples.CONTENT_URI, mdDeviceSamples.NICKNAME + " = ?",
            new String[] { account_nickname });
    Log.d(TAG, "Reset database, purged " + count + " rows.");

    bw_graphview.reset();/*  w ww . ja  v a  2s .  co m*/
    bw_graphview.update();
    loadavg_graphview.reset();
    loadavg_graphview.update();
    mem_graphview.reset();
    mem_graphview.update();

    ContentResolver resolver = getContentResolver();
    final Account account = new Account(account_nickname, mdConstants.ACCOUNT_TYPE);
    resolver.requestSync(account, mdContentProvider.AUTHORITY, new Bundle());
}

From source file:com.bjorsond.android.timeline.utilities.Utilities.java

public static Account getUserAccount(Context c) {
    AccountManager manager = AccountManager.get(c);
    Account[] accounts = manager.getAccountsByType("com.google");

    for (Account account : accounts) {
        return account;
    }// ww  w  .ja v a2 s .c om

    Account nonRegisteredAccount = new Account("test@timelineapp.no", "com.google");
    return nonRegisteredAccount;
}

From source file:org.microg.gms.auth.login.LoginActivity.java

private void retrieveRtToken(String oAuthToken) {
    new AuthRequest().fromContext(this).appIsGms().service("ac2dm").token(oAuthToken).isAccessToken()
            .addAccount().getAccountId().systemPartition().hasPermission().droidguardResults(null /*TODO*/)
            .getResponseAsync(new HttpFormClient.Callback<AuthResponse>() {
                @Override//from ww w . j  a  v  a  2  s  . c  o m
                public void onResponse(AuthResponse response) {
                    Account account = new Account(response.email, accountType);
                    if (accountManager.addAccountExplicitly(account, response.token, null)) {
                        accountManager.setAuthToken(account, "SID", response.Sid);
                        accountManager.setAuthToken(account, "LSID", response.LSid);
                        accountManager.setUserData(account, "flags", "1");
                        accountManager.setUserData(account, "services", response.services);
                        accountManager.setUserData(account, "oauthAccessToken", "1");
                        accountManager.setUserData(account, "firstName", response.firstName);
                        accountManager.setUserData(account, "lastName", response.lastName);
                        if (!TextUtils.isEmpty(response.accountId))
                            accountManager.setUserData(account, "GoogleUserId", response.accountId);

                        retrieveGmsToken(account);
                        setResult(RESULT_OK);
                    } else {
                        showError(R.string.auth_general_error_desc);
                        Log.w(TAG, "Account NOT created!");
                        setResult(RESULT_CANCELED);
                        // TODO: Give the user a chance to read the message :)
                        finish();
                    }
                }

                @Override
                public void onException(Exception exception) {
                    Log.w(TAG, "onException: " + exception);
                }
            });
}

From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java

@Override
public boolean isUserAnonymous(Context ctx) {
    AccountManager am = AccountManager.get(ctx);
    Account account = new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx));
    String authority = am.getUserData(account, Constants.KEY_AUTHORITY);
    return Constants.TOKEN_TYPE_ANONYMOUS.equals(authority);
}

From source file:com.creationgroundmedia.popularmovies.sync.MovieSyncAdapter.java

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)) {

        /*/*  w  w w .  ja v a  2 s .  com*/
         * 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:eu.iescities.pilot.rovereto.roveretoexplorer.custom.data.DTHelper.java

/**
 * Enable auot sync for the activity life-cycle
 * /*from w  w w  .j a v  a2  s.  co m*/
 * @throws NameNotFoundException
 * @throws DataException
 */
public static void activateAutoSync() {
    try {
        String authority = Constants.getAuthority(mContext);
        Account account = new Account(eu.trentorise.smartcampus.ac.Constants.getAccountName(mContext),
                eu.trentorise.smartcampus.ac.Constants.getAccountType(mContext));

        ContentResolver.setIsSyncable(account, authority, 1);
        ContentResolver.setSyncAutomatically(account, authority, true);
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), Constants.SYNC_INTERVAL * 60);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.clearcenter.mobile_demo.mdAuthenticatorActivity.java

private void finishLogin(String authToken) {
    Log.i(TAG, "finishLogin()");

    final Account account = new Account(nickname, mdConstants.ACCOUNT_TYPE);
    if (request_new_account) {
        account_manager.addAccountExplicitly(account, authToken, null);
        account_manager.setUserData(account, "hostname", hostname);
        account_manager.setUserData(account, "username", username);

        // Set system info sync for this account.
        final Bundle extras = new Bundle();
        ContentResolver.setSyncAutomatically(account, mdContentProvider.AUTHORITY, true);
        if (android.os.Build.VERSION.SDK_INT >= 8) {
            ContentResolver.addPeriodicSync(account, mdContentProvider.AUTHORITY, extras, 10);
        }/*  w w w.j  av  a  2  s  .c  o  m*/
    } else
        account_manager.setPassword(account, authToken);

    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, nickname);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, mdConstants.ACCOUNT_TYPE);
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);

    ContentResolver.requestSync(account, mdContentProvider.AUTHORITY, new Bundle());

    finish();
}

From source file:es.ugr.swad.swadroid.modules.notifications.Notifications.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.expandablelist_items_pulltorefresh);

    getSupportActionBar().setIcon(R.drawable.notif);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }/*from w  w w .  j  a  v a 2  s .  co  m*/

    this.findViewById(R.id.groupSpinner).setVisibility(View.GONE);

    refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container_expandablelist);
    list = (ExpandableListView) findViewById(R.id.expandablelist_pulltorefresh);
    emptyNotifTextView = (TextView) findViewById(R.id.list_item_title);
    mBirthdayLayout = (LinearLayout) findViewById(R.id.birthday_layout);
    mBirthdayTextView = (TextView) findViewById(R.id.birthdayTextView);

    groupItem = new ArrayList<String>();
    childItem = new ArrayList<List<Model>>();

    //Init ExpandableListView
    initSwipeOptions();

    //Set ExpandableListView data
    setGroupData();
    setChildGroupData();

    /*
     * If there aren't notifications to show, hide the notifications list
     * and show the empty notifications message
     */
    if (dbHelper.getAllRowsCount(DataBaseHelper.DB_TABLE_NOTIFICATIONS) == 0) {
        Log.d(TAG, "[onCreate] Notifications table is empty");

        emptyNotifTextView.setText(R.string.notificationsEmptyListMsg);
        emptyNotifTextView.setVisibility(View.VISIBLE);

        list.setOnChildClickListener(null);
        list.setVisibility(View.GONE);
    } else {
        Log.d(TAG, "[onCreate] Notifications table is not empty");

        emptyNotifTextView.setVisibility(View.GONE);
        list.setVisibility(View.VISIBLE);
    }

    setMETHOD_NAME("getNotifications");
    receiver = new SyncReceiver(this);
    account = new Account(getString(R.string.app_name), accountType);
}

From source file:org.pixmob.appengine.client.AppEngineClient.java

public void setAccount(String accountName) {
    if (accountName == null) {
        throw new IllegalArgumentException("Account name is required");
    }/*from w w  w.ja v  a2  s  .c  o m*/
    if (account != null && !account.name.equals(accountName)) {
        // reset authentication cookie since account name is different
        authenticationCookie = null;
    }
    account = new Account(accountName, GOOGLE_ACCOUNT_TYPE);
}

From source file:org.xwiki.android.authenticator.auth.AuthenticatorActivity.java

public void finishLogin(Intent intent) {
    Log.d(TAG, "> finishLogin");

    //before add new account, clear old account data.
    clearOldAccount();//from   w  w  w . j  ava2 s  .  co  m

    //get values
    String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
    String accountPassword = intent.getStringExtra(PARAM_USER_PASS);
    String accountServer = intent.getStringExtra(PARAM_USER_SERVER);

    // Creating the account on the device and setting the auth token we got
    // (Not setting the auth token will cause another call to the server to authenticate the user)
    Log.d(TAG, "finishLogin > addAccountExplicitly" + " "
            + intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
    final Account account = new Account(accountName, Constants.ACCOUNT_TYPE);
    mAccountManager.addAccountExplicitly(account, accountPassword, null);
    mAccountManager.setUserData(account, AccountManager.KEY_USERDATA, accountName);
    mAccountManager.setUserData(account, AccountManager.KEY_PASSWORD, accountPassword);
    mAccountManager.setUserData(account, AuthenticatorActivity.PARAM_USER_SERVER, accountServer);

    //grant permission if adding user from the third-party app (UID,PackageName);
    String packaName = getIntent().getStringExtra(PARAM_APP_PACKAGENAME);
    int uid = getIntent().getIntExtra(PARAM_APP_UID, 0);
    Log.d(TAG, packaName + ", " + getPackageName());
    //only if adding account from the third-party apps exclude android.uid.system, this will execute to grant permission and set token
    if (!packaName.contains("android.uid.system")) {
        AppContext.addAuthorizedApp(uid, packaName);
        String authToken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN);
        if (!TextUtils.isEmpty(authToken)) {
            String authTokenType = getIntent().getStringExtra(KEY_AUTH_TOKEN_TYPE);
            mAccountManager.setAuthToken(account, authTokenType, authToken);
        }
    }

    //return value to AccountManager
    Intent intentReturn = new Intent();
    intentReturn.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
    intentReturn.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName);
    setAccountAuthenticatorResult(intentReturn.getExtras());
    setResult(RESULT_OK, intentReturn);
    Log.d(TAG, ">" + "finish return");
    // in SettingSyncViewFlipper this activity finish;
}