Example usage for android.content ContentResolver addPeriodicSync

List of usage examples for android.content ContentResolver addPeriodicSync

Introduction

In this page you can find the example usage for android.content ContentResolver addPeriodicSync.

Prototype

public static void addPeriodicSync(Account account, String authority, Bundle extras, long pollFrequency) 

Source Link

Document

Specifies that a sync should be requested with the specified the account, authority, and extras at the given frequency.

Usage

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

/**
 * Helper method to schedule the sync adapter periodic execution
 *///from  ww w.java  2  s .com
public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
    Account account = getSyncAccount(context);
    String authority = context.getString(R.string.sync_provider_authority);
    if (syncInterval == -1) {
        ContentResolver.setSyncAutomatically(account, context.getString(R.string.sync_provider_authority),
                false);
    } else {
        ContentResolver.setSyncAutomatically(account, context.getString(R.string.sync_provider_authority),
                true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // we can enable inexact timers in our periodic sync
            SyncRequest request = new SyncRequest.Builder().syncPeriodic(syncInterval, flexTime)
                    .setSyncAdapter(account, authority).setExtras(new Bundle()).build();
            ContentResolver.requestSync(request);
        } else {
            ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
        }
    }
}

From source file:github.daneren2005.dsub.fragments.SettingsFragment.java

@Override
protected void onInitPreferences(PreferenceScreen preferenceScreen) {
    this.setTitle(preferenceScreen.getTitle());

    internalSSID = Util.getSSID(context);
    if (internalSSID == null) {
        internalSSID = "";
    }//from w w w  .  jav a  2  s. com
    internalSSIDDisplay = context.getResources().getString(R.string.settings_server_local_network_ssid_hint,
            internalSSID);

    theme = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_THEME);
    maxBitrateWifi = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI);
    maxBitrateMobile = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE);
    maxVideoBitrateWifi = (ListPreference) this
            .findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_WIFI);
    maxVideoBitrateMobile = (ListPreference) this
            .findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_MOBILE);
    networkTimeout = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT);
    cacheLocation = (CacheLocationPreference) this.findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION);
    preloadCountWifi = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_WIFI);
    preloadCountMobile = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_MOBILE);
    keepPlayedCount = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_KEEP_PLAYED_CNT);
    tempLoss = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_TEMP_LOSS);
    pauseDisconnect = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_PAUSE_DISCONNECT);
    serversCategory = (PreferenceCategory) this.findPreference(Constants.PREFERENCES_KEY_SERVER_KEY);
    addServerPreference = this.findPreference(Constants.PREFERENCES_KEY_SERVER_ADD);
    videoPlayer = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_VIDEO_PLAYER);
    songPressAction = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_SONG_PRESS_ACTION);
    syncInterval = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_INTERVAL);
    syncEnabled = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED);
    syncWifi = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_WIFI);
    syncNotification = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_NOTIFICATION);
    syncStarred = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_STARRED);
    syncMostRecent = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT);
    replayGain = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN);
    replayGainType = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_TYPE);
    replayGainBump = this.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP);
    replayGainUntagged = this.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED);
    cacheSize = (EditTextPreference) this.findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE);
    openToTab = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_OPEN_TO_TAB);

    settings = Util.getPreferences(context);
    serverCount = settings.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1);

    if (cacheSize != null) {
        this.findPreference("clearCache")
                .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Util.confirmDialog(context, R.string.common_delete,
                                R.string.common_confirm_message_cache, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        new LoadingTask<Void>(context, false) {
                                            @Override
                                            protected Void doInBackground() throws Throwable {
                                                FileUtil.deleteMusicDirectory(context);
                                                FileUtil.deleteSerializedCache(context);
                                                FileUtil.deleteArtworkCache(context);
                                                FileUtil.deleteAvatarCache(context);
                                                return null;
                                            }

                                            @Override
                                            protected void done(Void result) {
                                                Util.toast(context, R.string.settings_cache_clear_complete);
                                            }

                                            @Override
                                            protected void error(Throwable error) {
                                                Util.toast(context, getErrorMessage(error), false);
                                            }
                                        }.execute();
                                    }
                                });
                        return false;
                    }
                });
    }

    if (syncEnabled != null) {
        this.findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED)
                .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        Boolean syncEnabled = (Boolean) newValue;

                        Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE);
                        ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY,
                                syncEnabled);
                        ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY,
                                syncEnabled);

                        return true;
                    }
                });
        syncInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Integer syncInterval = Integer.parseInt(((String) newValue));

                Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE);
                ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY,
                        new Bundle(), 60L * syncInterval);
                ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY, new Bundle(),
                        60L * syncInterval);

                return true;
            }
        });
    }

    if (serversCategory != null) {
        addServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                serverCount++;
                int instance = serverCount;
                serversCategory.addPreference(addServer(serverCount));

                SharedPreferences.Editor editor = settings.edit();
                editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount);
                // Reset set folder ID
                editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + instance, null);
                editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + instance, "http://yourhost");
                editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + instance,
                        getResources().getString(R.string.settings_server_unused));
                editor.commit();

                ServerSettings ss = new ServerSettings(instance);
                serverSettings.put(String.valueOf(instance), ss);
                ss.update();

                return true;
            }
        });

        serversCategory.setOrderingAsAdded(false);
        for (int i = 1; i <= serverCount; i++) {
            serversCategory.addPreference(addServer(i));
            serverSettings.put(String.valueOf(i), new ServerSettings(i));
        }
    }

    SharedPreferences prefs = Util.getPreferences(context);
    prefs.registerOnSharedPreferenceChangeListener(this);

    update();
}

From source file:github.popeen.dsub.fragments.SettingsFragment.java

@Override
protected void onInitPreferences(PreferenceScreen preferenceScreen) {
    this.setTitle(preferenceScreen.getTitle());

    internalSSID = Util.getSSID(context);
    if (internalSSID == null) {
        internalSSID = "";
    }//from w w  w.ja va 2  s  .  c  o m
    internalSSIDDisplay = context.getResources().getString(R.string.settings_server_local_network_ssid_hint,
            internalSSID);

    theme = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_THEME);
    maxBitrateWifi = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI);
    maxBitrateMobile = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE);
    ;
    //maxVideoBitrateWifi = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_WIFI);
    //maxVideoBitrateMobile = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_MOBILE);
    networkTimeout = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT);
    cacheLocation = (CacheLocationPreference) this.findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION);
    preloadCountWifi = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_WIFI);
    preloadCountMobile = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_MOBILE);
    keepPlayedCount = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_KEEP_PLAYED_CNT);
    tempLoss = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_TEMP_LOSS);
    pauseDisconnect = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_PAUSE_DISCONNECT);
    serversCategory = (PreferenceCategory) this.findPreference(Constants.PREFERENCES_KEY_SERVER_KEY);
    addServerPreference = this.findPreference(Constants.PREFERENCES_KEY_SERVER_ADD);
    //videoPlayer = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_VIDEO_PLAYER);
    songPressAction = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_SONG_PRESS_ACTION);
    syncInterval = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_INTERVAL);
    syncEnabled = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED);
    syncWifi = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_WIFI);
    syncNotification = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_NOTIFICATION);
    syncStarred = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_STARRED);
    syncMostRecent = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT);
    replayGain = (CheckBoxPreference) this.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN);
    replayGainType = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_TYPE);
    replayGainBump = this.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP);
    replayGainUntagged = this.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED);
    cacheSize = (EditTextPreference) this.findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE);
    openToTab = (ListPreference) this.findPreference(Constants.PREFERENCES_KEY_OPEN_TO_TAB);

    settings = Util.getPreferences(context);
    serverCount = settings.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1);

    if (cacheSize != null) {
        this.findPreference("clearCache")
                .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Util.confirmDialog(context, R.string.common_delete,
                                R.string.common_confirm_message_cache, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        new LoadingTask<Void>(context, false) {
                                            @Override
                                            protected Void doInBackground() throws Throwable {
                                                FileUtil.deleteMusicDirectory(context);
                                                FileUtil.deleteSerializedCache(context);
                                                FileUtil.deleteArtworkCache(context);
                                                FileUtil.deleteAvatarCache(context);
                                                return null;
                                            }

                                            @Override
                                            protected void done(Void result) {
                                                Util.toast(context, R.string.settings_cache_clear_complete);
                                            }

                                            @Override
                                            protected void error(Throwable error) {
                                                Util.toast(context, getErrorMessage(error), false);
                                            }
                                        }.execute();
                                    }
                                });
                        return false;
                    }
                });
    }

    if (syncEnabled != null) {
        this.findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED)
                .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        Boolean syncEnabled = (Boolean) newValue;

                        Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE);
                        ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY,
                                syncEnabled);
                        ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY,
                                syncEnabled);

                        return true;
                    }
                });
        syncInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Integer syncInterval = Integer.parseInt(((String) newValue));

                Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE);
                ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY,
                        new Bundle(), 60L * syncInterval);
                ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PODCAST_AUTHORITY, new Bundle(),
                        60L * syncInterval);

                return true;
            }
        });
    }

    if (serversCategory != null) {
        addServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                serverCount++;
                int instance = serverCount;
                serversCategory.addPreference(addServer(serverCount));

                SharedPreferences.Editor editor = settings.edit();
                editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount);
                // Reset set folder ID
                editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + instance, null);
                editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + instance, "http://yourhost");
                editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + instance,
                        getResources().getString(R.string.settings_server_unused));
                editor.commit();

                ServerSettings ss = new ServerSettings(instance);
                serverSettings.put(String.valueOf(instance), ss);
                ss.update();

                return true;
            }
        });

        serversCategory.setOrderingAsAdded(false);
        for (int i = 1; i <= serverCount; i++) {
            serversCategory.addPreference(addServer(i));
            serverSettings.put(String.valueOf(i), new ServerSettings(i));
        }
    }

    SharedPreferences prefs = Util.getPreferences(context);
    prefs.registerOnSharedPreferenceChangeListener(this);

    update();
}

From source file:org.ohmage.authenticator.AuthenticatorActivity.java

/**
 * Called when response is received from the server for authentication
 * request. See onAuthenticationResult(). Sets the
 * AccountAuthenticatorResult which is sent back to the caller. Also sets
 * the authToken in AccountManager for this account.
 * //from w ww  . ja  v a 2  s .co m
 * @param the confirmCredentials result.
 */

protected void createAccount() {
    Log.v(TAG, "finishLogin()");
    final Account account = new Account(mUsername, OhmageApplication.ACCOUNT_TYPE);
    Bundle userData = new Bundle();
    userData.putString(KEY_OHMAGE_SERVER, ConfigHelper.serverUrl());
    mAuthtoken = mHashedPassword;

    if (TextUtils.isEmpty(mAuthtoken)) {
        Log.w(TAG, "Trying to create account with empty password");
        return;
    }

    if (mRequestNewAccount) {
        mAccountManager.addAccountExplicitly(account, mPassword, userData);
        mAccountManager.setAuthToken(account, OhmageApplication.AUTHTOKEN_TYPE, mAuthtoken);
        // Set sync for this account.
        ContentResolver.setIsSyncable(account, DbContract.CONTENT_AUTHORITY, 1);
        ContentResolver.setSyncAutomatically(account, DbContract.CONTENT_AUTHORITY, true);
        ContentResolver.addPeriodicSync(account, DbContract.CONTENT_AUTHORITY, new Bundle(), 3600);
    } else {
        mAccountManager.setPassword(account, mPassword);
    }
    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, OhmageApplication.ACCOUNT_TYPE);
    if (mAuthtokenType != null && mAuthtokenType.equals(OhmageApplication.AUTHTOKEN_TYPE)) {
        intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken);
    }
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);

    mPreferencesHelper.edit().putLoginTimestamp(System.currentTimeMillis()).commit();

    if (UserPreferencesHelper.isSingleCampaignMode()) {
        // Download the single campaign
        showDialog(DIALOG_DOWNLOADING_CAMPAIGNS);
        getSupportLoaderManager().restartLoader(0, null, this);
    } else {
        finishLogin();
    }
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventsListActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    //Forces our onResume() function to do a DB call rather than a full HTTP request just cos we returned
    //from one of our subscreens
    //resumeOnResultPollAPI = false;
    BackupManager bm = null;//from  w  ww  .  ja v a  2  s .co  m
    try {
        bm = new BackupManager(this);
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "onActivityResult BackupManager",
                e);
    }

    switch (requestCode) {
    case LAUNCHSETTINGS: {
        settings = PreferenceManager.getDefaultSharedPreferences(this);

        try {
            Intent intent = new Intent(this, ZenossPoller.class);
            intent.putExtra("settingsUpdate", true);
            startService(intent);
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                    "onActivityResult startService", e);
        }

        try {
            bm.dataChanged();
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                    "onActivityResult bm.dataChanged()", e);
        }

        //SyncAdapter stuff
        if (null != mAccount) {
            try {
                mResolver = getContentResolver();
                Bundle bndle = new Bundle();
                ContentResolver.addPeriodicSync(mAccount, AUTHORITY, bndle, 86400);

                ContentResolver.setSyncAutomatically(mAccount, AUTHORITY,
                        settings.getBoolean("refreshCache", true));

                /*bndle.putBoolean(
                        ContentResolver.SYNC_EXTRAS_MANUAL, true);
                bndle.putBoolean(
                        ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
                        
                Log.e("addPeriodicSync","Requesting a full sync!");
                ContentResolver.requestSync(mAccount, AUTHORITY, bndle);*/
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                        "onActivityResult LAUNCHSETTINGS", e);
            }
        } else {
            //Log.e("addPeriodicSync","mAccount was null");
        }
    }
        break;

    case ZenossAPI.ACTIVITYRESULT_PUSHCONFIG: {
        try {
            GCMRegistrar.unregister(this);

            if (PreferenceManager.getDefaultSharedPreferences(ViewZenossEventsListActivity.this)
                    .getBoolean(ZenossAPI.PREFERENCE_PUSH_ENABLED, false))
                doGCMRegistration();
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                    "onActivityResult ACTIVITYRESULT_PUSHCONFIG", e);
        }
    }
        break;

    default: {
        if (resultCode == 1) {
            try {
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("FirstRun", false);
                editor.commit();
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "onActivityResult default",
                        e);
            }

            //Also update our onResume helper bool although it should already be set
            firstRun = false;
            AlertDialog.Builder builder = null;
            AlertDialog welcomeDialog = null;
            try {
                builder = new AlertDialog.Builder(this);
                builder.setMessage(
                        "Additional settings and functionality can be found by pressing the Action bar overflow.\r\n"
                                + "\r\nIf you experience issues please email;\r\nGareth@DataSift.com before leaving negative reviews.")
                        .setTitle("Welcome to Rhybudd!").setCancelable(true)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                finishStart();
                            }
                        });
                welcomeDialog = builder.create();
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "onActivityResult default",
                        e);
            }

            try {
                welcomeDialog.show();
            } catch (Exception e) {
                finishStart();
                BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                        "OnActivityResult welcomedialog", e);
            }

            try {
                bm.dataChanged();
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "onActivityResult default",
                        e);
            }
        } else if (resultCode == 2) {
            try {
                Toast.makeText(ViewZenossEventsListActivity.this,
                        getResources().getString(R.string.FirstRunNeedSettings), Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                        "onActivityResult resultcode 2", e);
            }
            finish();
        }
        //Who knows what happened here - quit
        else {
            //Toast.makeText(ViewZenossEventsListActivity.this, getResources().getString(R.string.FirstRunNeedSettings), Toast.LENGTH_LONG).show();
            //finish();
        }
    }
        break;
    }
}

From source file:com.openerp.MainActivity.java

/**
 * Sets the sync periodic./*from   w ww. j  a  v a 2  s . co  m*/
 * 
 * @param authority
 *            the authority
 * @param interval_in_minute
 *            the interval_in_minute
 * @param seconds_per_minute
 *            the seconds_per_minute
 * @param milliseconds_per_second
 *            the milliseconds_per_second
 */
public void setSyncPeriodic(String authority, long interval_in_minute, long seconds_per_minute,
        long milliseconds_per_second) {
    Account account = OpenERPAccountManager.getAccount(this, OEUser.current(mContext).getAndroidName());
    Bundle extras = new Bundle();
    this.setAutoSync(authority, true);
    ContentResolver.setIsSyncable(account, authority, 1);
    final long sync_interval = interval_in_minute * seconds_per_minute * milliseconds_per_second;
    ContentResolver.addPeriodicSync(account, authority, extras, sync_interval);
}

From source file:org.ohmage.auth.AuthenticatorActivity.java

private Account addOrFindAccount(String email, String password) {
    Account[] accounts = am.getAccountsByType(AuthUtil.ACCOUNT_TYPE);
    Account account = accounts.length != 0 ? accounts[0] : new Account(email, AuthUtil.ACCOUNT_TYPE);

    if (accounts.length == 0) {
        am.addAccountExplicitly(account, password, null);

        // Turn on automatic syncing for this account
        ContentResolver.setSyncAutomatically(account, OhmageContract.CONTENT_AUTHORITY, true);
        ContentResolver.addPeriodicSync(account, StreamContract.CONTENT_AUTHORITY, new Bundle(),
                AuthUtil.SYNC_INTERVAL);

        ContentResolver.setSyncAutomatically(account, StreamContract.CONTENT_AUTHORITY, true);
        ContentResolver.addPeriodicSync(account, StreamContract.CONTENT_AUTHORITY, new Bundle(),
                AuthUtil.SYNC_INTERVAL);

        ContentResolver.setSyncAutomatically(account, ResponseContract.CONTENT_AUTHORITY, true);
        ContentResolver.addPeriodicSync(account, ResponseContract.CONTENT_AUTHORITY, new Bundle(),
                AuthUtil.SYNC_INTERVAL);

        ContentResolver.setSyncAutomatically(account, AppLogSyncAdapter.CONTENT_AUTHORITY, true);
        ContentResolver.addPeriodicSync(account, AppLogSyncAdapter.CONTENT_AUTHORITY, new Bundle(),
                AuthUtil.SYNC_INTERVAL);
    } else {//  w  ww  . ja va2s .  c om
        am.setPassword(accounts[0], password);
    }
    return account;
}

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

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

    new SilentBackgroundTask<Void>(this) {
        @Override/*w ww  . jav  a2  s.  c  om*/
        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

/**
 * Helper method to schedule the sync adapter periodic execution
 *//* w  w  w. j a v  a  2  s  .c o m*/
public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
    Account account = getSyncAccount(context);
    String authority = context.getString(R.string.content_authority);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // we can enable inexact timers in our periodic sync
        SyncRequest request = new SyncRequest.Builder().syncPeriodic(syncInterval, flexTime)
                .setSyncAdapter(account, authority).build();
        ContentResolver.requestSync(request);
    } else {
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
    }
}