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.ntsync.android.sync.syncadapter.SyncAdapter.java

private void notifyUserPhotoNotSynced(String accountName) {
    Account account = new Account(accountName, Constants.ACCOUNT_TYPE);
    AccountManager acm = AccountManager.get(mContext);
    String synced = acm.getUserData(account, NOTIF_SHOWN_PHOTO_SYNCED);
    if (synced == null) {
        Intent shopIntent = new Intent(mContext, ShopActivity.class);
        shopIntent.putExtra(ShopActivity.PARM_ACCOUNT_NAME, accountName);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
        stackBuilder.addParentStack(ShopActivity.class);
        stackBuilder.addNextIntent(shopIntent);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext)
                .setSmallIcon(Constants.NOTIF_ICON)
                .setContentTitle(getText(R.string.notif_photonotsynced_title)).setContentText(accountName)
                .setAutoCancel(true)//from  ww  w.j a  va2  s. c om
                .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT))
                .setOnlyAlertOnce(true);
        NotificationManager mNotificationManager = (NotificationManager) mContext
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(Constants.NOTIF_PHOTO_NOT_SYNCED, mBuilder.build());
        acm.setUserData(account, NOTIF_SHOWN_PHOTO_SYNCED, String.valueOf(System.currentTimeMillis()));
    }
}

From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java

private void notifyUserConctactNotSynced(int maxCount, int totalLocalContacts, String accountName) {
    AccountManager acm = AccountManager.get(mContext);
    Account account = new Account(accountName, Constants.ACCOUNT_TYPE);
    String lastTimeShown = acm.getUserData(account, NOTIF_SHOWN_CONTACTS_SYNCED);
    Long lastTime;/*from  ww w.j ava  2 s  .  c o  m*/
    try {
        lastTime = lastTimeShown != null ? Long.parseLong(lastTimeShown) : null;
    } catch (NumberFormatException ex) {
        LogHelper.logWCause(TAG,
                "Invalid Config-Settings:" + NOTIF_SHOWN_CONTACTS_SYNCED + " Value:" + lastTimeShown, ex);
        lastTime = null;
    }

    if (lastTime == null || System.currentTimeMillis() > lastTime.longValue() + NOTIF_WAIT_TIME) {
        // Create Shop-Intent
        Intent shopIntent = new Intent(mContext, ShopActivity.class);
        shopIntent.putExtra(ShopActivity.PARM_ACCOUNT_NAME, account.name);
        // Adds the back stack
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
        stackBuilder.addParentStack(ShopActivity.class);
        stackBuilder.addNextIntent(shopIntent);

        // Create Notification
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext)
                .setSmallIcon(Constants.NOTIF_ICON)
                .setContentTitle(String.format(getText(R.string.notif_contactnotsynced_title), maxCount,
                        totalLocalContacts))
                .setContentText(String.format(getText(R.string.notif_contactnotsynced_content), account.name))
                .setAutoCancel(true).setOnlyAlertOnce(true)
                .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
        NotificationManager mNotificationManager = (NotificationManager) mContext
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(Constants.NOTIF_CONTACTS_NOT_SYNCED, mBuilder.build());
        acm.setUserData(account, NOTIF_SHOWN_CONTACTS_SYNCED, String.valueOf(System.currentTimeMillis()));
    }
}

From source file:org.linphone.ContactsManager.java

public void initializeSyncAccount(Context context, ContentResolver contentResolver) {
    initializeContactManager(context, contentResolver);
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    Account[] accounts = accountManager.getAccountsByType(context.getPackageName());

    if (accounts != null && accounts.length == 0) {
        Account newAccount = new Account(context.getString(R.string.sync_account_name),
                context.getPackageName());
        try {// ww w .j ava2s  . c om
            accountManager.addAccountExplicitly(newAccount, null, null);
            mAccount = newAccount;
        } catch (Exception e) {
            Log.e(e);
            mAccount = null;
        }
    } else {
        mAccount = accounts[0];
    }
    initializeContactManager(context, contentResolver);
}

From source file:br.com.bioscada.apps.biotracks.TrackListActivity.java

@Override
public void onConfirmSyncDone(boolean enable) {
    if (enable) {
        String googleAccount = PreferencesUtils.getString(this, R.string.google_account_key,
                PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
        enableSync(new Account(googleAccount, Constants.ACCOUNT_TYPE));
    }/*from  w  ww .java 2 s . co  m*/
}

From source file:org.kontalk.ui.NumberValidation.java

private void completeLogin(String serverUri, String challenge, byte[] privateKeyData, byte[] publicKeyData,
        Map<String, Keyring.TrustedFingerprint> trustedKeys) {
    // generate the bridge certificate
    byte[] bridgeCertData;
    try {//from   w w  w.  j  ava 2  s. co m
        bridgeCertData = X509Bridge.createCertificate(privateKeyData, publicKeyData, mPassphrase).getEncoded();
    } catch (Exception e) {
        // abort
        throw new RuntimeException("unable to build X.509 bridge certificate", e);
    }

    final Account account = new Account(mPhoneNumber, Authenticator.ACCOUNT_TYPE);

    // workaround for bug in AccountManager (http://stackoverflow.com/a/11698139/1045199)
    // procedure will continue in removeAccount callback
    mAccountManager.removeAccount(account, new AccountRemovalCallback(this, account, mPassphrase,
            privateKeyData, publicKeyData, bridgeCertData, mName, serverUri, challenge, trustedKeys), mHandler);
}

From source file:github.popeen.dsub.activity.SubsonicFragmentActivity.java

private void createAccount() {
    final Context context = this;

    new SilentBackgroundTask<Void>(this) {
        @Override/* ww w. j a v  a  2  s.  co  m*/
        protected Void doInBackground() throws Throwable {
            AccountManager accountManager = (AccountManager) context.getSystemService(ACCOUNT_SERVICE);
            Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE);
            accountManager.addAccountExplicitly(account, null, null);

            SharedPreferences prefs = Util.getPreferences(context);
            boolean syncEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SYNC_ENABLED, true);
            int syncInterval = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_SYNC_INTERVAL, "60"));

            // Add enabled/frequency to playlist/podcasts syncing
            ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY,
                    syncEnabled);
            ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, new Bundle(),
                    60L * syncInterval);
            ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY,
                    syncEnabled);
            ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY, new Bundle(),
                    60L * syncInterval);

            // Add for starred/recently added
            ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_STARRED_AUTHORITY,
                    (syncEnabled && prefs.getBoolean(Constants.PREFERENCES_KEY_SYNC_STARRED, false)));
            ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_STARRED_AUTHORITY, new Bundle(),
                    60L * syncInterval);
            ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_MOST_RECENT_AUTHORITY,
                    (syncEnabled && prefs.getBoolean(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT, false)));
            ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_MOST_RECENT_AUTHORITY, new Bundle(),
                    60L * syncInterval);
            return null;
        }

        @Override
        protected void done(Void result) {

        }
    }.execute();
}

From source file:com.glandorf1.joe.wsprnetviewer.app.sync.WsprNetViewerSyncAdapter.java

/**
 * Create a new dummy account for the sync adapter
 *
 * @param context The application context
 *//* www  .  j av a2 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
    // app_name = WsprNetViewer
    // sync_account_type = wsprnetviewer.joe.glandorf1.com
    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.
        boolean ret = accountManager.addAccountExplicitly(newAccount, "", null);
        if (!ret) {
            return null;
        }

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

From source file:com.razza.apps.iosched.ui.BaseActivity.java

/**
 * Called when authentication succeeds. This may either happen because the user just
 * authenticated for the first time (and went through the sign in flow), or because it's
 * a returning user.//from  w  w  w .java  2  s  .  com
 *
 * @param accountName        name of the account that just authenticated successfully.
 * @param newlyAuthenticated If true, this user just authenticated for the first time.
 *                           If false, it's a returning user.
 */
@Override
public void onAuthSuccess(String accountName, boolean newlyAuthenticated) {
    Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    LogUtils.LOGD(TAG, "onAuthSuccess, account " + accountName + ", newlyAuthenticated=" + newlyAuthenticated);

    refreshAccountDependantData();

    if (newlyAuthenticated) {
        LogUtils.LOGD(TAG, "Enabling auto sync on content provider for account " + accountName);
        SyncHelper.updateSyncInterval(this, account);
        SyncHelper.requestManualSync(account);
    }

    setupAccountBox();
    populateNavDrawer();
    registerGCMClient();
}

From source file:com.google.samples.apps.iosched.ui.BaseActivity.java

/**
 * Called when authentication succeeds. This may either happen because the user just
 * authenticated for the first time (and went through the sign in flow), or because it's
 * a returning user./*w  w w .  ja v  a  2s . c o m*/
 *
 * @param accountName        name of the account that just authenticated successfully.
 * @param newlyAuthenticated If true, this user just authenticated for the first time.
 *                           If false, it's a returning user.
 */
@Override
public void onAuthSuccess(String accountName, boolean newlyAuthenticated) {
    Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    LOGD(TAG, "onAuthSuccess, account " + accountName + ", newlyAuthenticated=" + newlyAuthenticated);

    refreshAccountDependantData();

    if (newlyAuthenticated) {
        LOGD(TAG, "Enabling auto sync on content provider for account " + accountName);
        SyncHelper.updateSyncInterval(this, account);
        SyncHelper.requestManualSync(account);
    }

    setupAccountBox();
    populateNavDrawer();
    registerGCMClient();
}

From source file:xyz.template.material.menu.ui.BaseActivity.java

/**
 * Called when authentication succeeds. This may either happen because the user just
 * authenticated for the first time (and went through the sign in flow), or because it's
 * a returning user./* w  ww.  j a v a 2s .  c om*/
 * @param accountName name of the account that just authenticated successfully.
 * @param newlyAuthenticated If true, this user just authenticated for the first time.
 * If false, it's a returning user.
 */
@Override
public void onAuthSuccess(String accountName, boolean newlyAuthenticated) {
    Account account = new Account(accountName, "com.google");
    LOGD(TAG, "onAuthSuccess, account " + accountName + ", newlyAuthenticated=" + newlyAuthenticated);

    refreshAccountDependantData();

    if (newlyAuthenticated) {
        LOGD(TAG, "Enabling auto sync on content provider for account " + accountName);
        //            SyncHelper.updateSyncInterval(this, account);
        //            SyncHelper.requestManualSync(account);
    }

    setupAccountBox();
    populateNavDrawer();
    registerGCMClient();
}