當前位置: 首頁>>代碼示例>>Java>>正文


Java ContentResolver.setSyncAutomatically方法代碼示例

本文整理匯總了Java中android.content.ContentResolver.setSyncAutomatically方法的典型用法代碼示例。如果您正苦於以下問題:Java ContentResolver.setSyncAutomatically方法的具體用法?Java ContentResolver.setSyncAutomatically怎麽用?Java ContentResolver.setSyncAutomatically使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.ContentResolver的用法示例。


在下文中一共展示了ContentResolver.setSyncAutomatically方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onAccountCreated

import android.content.ContentResolver; //導入方法依賴的package包/類
private static void onAccountCreated(Account newAccount, Context context) {
    /*
     * Since we've created an account
     */
    configurePeriodicSync(context, Prefs.getSyncInterval(), SYNC_FLEXTIME);

    /*
     * Without calling setSyncAutomatically, our periodic sync will not be enabled.
     */
    ContentResolver.setSyncAutomatically(newAccount, AUTHORITY, true);

    /*
     * Finally, let's do a sync to get things started
     */
    //syncImmediately(context);
}
 
開發者ID:jamesddube,項目名稱:LaravelNewsApp,代碼行數:17,代碼來源:SyncAdapter.java

示例2: updateSync

import android.content.ContentResolver; //導入方法依賴的package包/類
/**
 * Updates ContentResolver sync settings for an Account's specified SyncAdapter.
 *
 * <p>Sets an accounts SyncAdapter (selected based on authority) to sync/not-sync automatically
 * and immediately requests/cancels a sync.
 *
 * <p>updateSync should always be called under {@link AccountSnippet#mLock} write lock to avoid
 * flapping between the getSyncAutomatically and setSyncAutomatically calls.
 *
 * @param account A Google Account.
 * @param authority The authority of a content provider that should (not) be synced.
 * @param sync Whether or not the account's content provider should be synced.
 */
private void updateSync(Account account, String authority, boolean sync) {
    if (ContentResolver.getSyncAutomatically(account, authority) != sync) {
        ContentResolver.setSyncAutomatically(account, authority, sync);
        if (sync) {
            ContentResolver.requestSync(account, authority, new Bundle());
        } else {
            ContentResolver.cancelSync(account, authority);
        }
        Log.i(
                "Set sync to "
                        + sync
                        + " for account "
                        + account
                        + ", adapter "
                        + authority
                        + ".");
    }
}
 
開發者ID:google,項目名稱:mobly-bundled-snippets,代碼行數:32,代碼來源:AccountSnippet.java

示例3: onAccountCreated

import android.content.ContentResolver; //導入方法依賴的package包/類
private static void onAccountCreated(Account newAccount, Context context) {
    /*
     * Since we've created an account
     */
    SunshineSyncAdapter.configurePeriodicSync(context, SYNC_INTERVAL, SYNC_FLEXTIME);

    /*
     * Without calling setSyncAutomatically, our periodic sync will not be enabled.
     */
    ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true);

    /*
     * Finally, let's do a sync to get things started
     */
    syncImmediately(context);
}
 
開發者ID:changja88,項目名稱:Udacity_Sunshine,代碼行數:17,代碼來源:SunshineSyncAdapter.java

示例4: init

import android.content.ContentResolver; //導入方法依賴的package包/類
public static void init(Context context) {
    Account account = makeAccount(context);
    AccountManager accountManager =
            (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    if (accountManager.addAccountExplicitly(account, null, null)) {
        ContentResolver.setSyncAutomatically(account, GigApplication.getSyncAuthority(), true);
        int syncPeriod = BuildConfig.DEBUG ? DEBUG_SYNC_PERIOD_HOURS : SYNC_PERIOD_HOURS;
        ContentResolver.addPeriodicSync(account, GigApplication.getSyncAuthority(), Bundle.EMPTY,
                TimeUnit.HOURS.toSeconds(syncPeriod));
    }

    if (ContentResolver.getIsSyncable(account, GigApplication.getSyncAuthority()) <= 0) {
        if (BuildConfig.DEBUG) {
            Log.d(LOG_TAG, "setIsSyncable");
        }

        ContentResolver.setIsSyncable(account, GigApplication.getSyncAuthority(), 1);
    }
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:21,代碼來源:SyncManager.java

示例5: createSyncAccount

import android.content.ContentResolver; //導入方法依賴的package包/類
/**
 * Create an entry for this application in the system account list,
 * if it isn't already there.
 *
 * @param context Context
 */
public static void createSyncAccount(Context context) {

    // Create account, if it's missing. (Either first run, or user has deleted account.)
    Account account = new Account(ACCOUNT_NAME, SyncUtils.ACCOUNT_TYPE);
    AccountManager accountManager =
            (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    if (accountManager.addAccountExplicitly(account, null, null)) {
        // Inform the system that this account supports sync
        ContentResolver.setIsSyncable(account, CONTENT_AUTHORITY, 1);
        // Inform the system that this account is eligible for auto sync when the network is up
        ContentResolver.setSyncAutomatically(account, CONTENT_AUTHORITY, true);
        // Recommend a schedule for automatic synchronization. The system may modify this based
        // on other scheduled syncs and network utilization.
        ContentResolver.addPeriodicSync(account, CONTENT_AUTHORITY,
                new Bundle(), SYNC_FREQUENCY);
        Log.i(TAG, "Account added successfully!");
        // newAccount = true;
    } else {
        Log.d(TAG, "Account already added, not adding again...");
    }
}
 
開發者ID:jaydeepw,項目名稱:simplest-sync-adapter,代碼行數:28,代碼來源:SyncUtils.java

示例6: onAccountCreated

import android.content.ContentResolver; //導入方法依賴的package包/類
private static void onAccountCreated(Account newAccount, Context context, int syncInterval, int syncFlexTime) {
    // Since we've created an account
    SyncAdapter.configurePeriodicSync(context, syncInterval, syncFlexTime);

    // Without calling setSyncAutomatically, our periodic sync will not be enabled
    ContentResolver.setSyncAutomatically(newAccount,
            context.getString(R.string.rnsb_content_authority), true);
}
 
開發者ID:ferrannp,項目名稱:react-native-sync-adapter,代碼行數:9,代碼來源:SyncAdapter.java

示例7: getOrCreateAccount

import android.content.ContentResolver; //導入方法依賴的package包/類
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
  AccountManager accountManager = AccountManager.get(context);
  Account[]      accounts       = accountManager.getAccountsByType("im.cable.cableim");

  Optional<AccountHolder> account;

  if (accounts.length == 0) account = createAccount(context);
  else                      account = Optional.of(new AccountHolder(accounts[0], false));

  if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
    ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
  }

  return account;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:16,代碼來源:DirectoryHelper.java

示例8: onAccountCreated

import android.content.ContentResolver; //導入方法依賴的package包/類
private static void onAccountCreated(Account newAccount, Context context) {
    final long interval =  PreferencesHelper.getInstance()
            .getSyncInterval(context.getString(R.string.pref_auto_sync_interval_key));
    //Since we've created an account
    TvGuideSyncAdapter.configurePeriodicSync(context, interval, interval / FLEX_DIVIDER);
    //Without calling setSyncAutomatically, our periodic sync will not be enabled.
    ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true);
    //Finally, let's do a sync to get things started
    syncImmediately(context);
}
 
開發者ID:graviton57,項目名稱:TVGuide,代碼行數:11,代碼來源:TvGuideSyncAdapter.java

示例9: syncAutomatically

import android.content.ContentResolver; //導入方法依賴的package包/類
/**
 * The {@link ContentResolver#setSyncAutomatically} and {@link ContentResolver#addPeriodicSync}
 * must call programmatically
 */
private void syncAutomatically() {
    //get all account related to our app
    final Account availableAccounts[] = accountManager.getAccountsByType(AUTHTOKEN_TYPE_FULL_ACCESS);

    //set syncable status for all of them
    for (Account account : availableAccounts) {
        ContentResolver.setIsSyncable(account, GlobalConstant.AUTHORITY, 1);
        ContentResolver.setSyncAutomatically(account, GlobalConstant.AUTHORITY, true);
        ContentResolver.addPeriodicSync(account, GlobalConstant.AUTHORITY, new Bundle(), 2 * 60 * 60);
    }
}
 
開發者ID:6thsolution,項目名稱:EasyAppleSyncAdapter,代碼行數:16,代碼來源:MainActivity.java

示例10: createAccount

import android.content.ContentResolver; //導入方法依賴的package包/類
private void createAccount(String accessToken, String accountName) {
    mLogger.debug("AUTH", "Creating account %s", accountName);
    Intent intent = getIntent();
    Account account = new Account(accountName, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
    if (intent.getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false)) {
        mAccountManager.addAccountExplicitly(account, null, null);

        ContentResolver.setIsSyncable(account, CalendarContract.AUTHORITY, 1);
        ContentResolver.setSyncAutomatically(account, CalendarContract.AUTHORITY, true);
    }

    Uri icalUri = Uri.parse(mBDayCalendar);
    String key = icalUri.getQueryParameter("key");
    String uid = icalUri.getQueryParameter("uid");
    if (key == null || key.isEmpty() || uid == null || uid.isEmpty()) {
        mLogger.error("AUTH", "Failed to retrieve iCal URL! The raw URL was " + mBDayCalendar);
        Toast.makeText(this, getString(R.string.auth_calendar_uri_error_toast), Toast.LENGTH_SHORT)
                .show();
        finish();
        return;
    }
    mAccountManager.setUserData(account, Authenticator.DATA_BDAY_URI, null); // clear the legacy storage
    mAccountManager.setAuthToken(account, Authenticator.FB_OAUTH_TOKEN, accessToken);
    mAccountManager.setAuthToken(account, Authenticator.FB_KEY_TOKEN, key);
    mAccountManager.setAuthToken(account, Authenticator.FB_UID_TOKEN, uid);

    Intent result = new Intent();
    result.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName);
    result.putExtra(AccountManager.KEY_ACCOUNT_TYPE, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
    String authTokenType = intent.getStringExtra(AuthenticatorActivity.ARG_AUTH_TOKEN_TYPE);
    if (authTokenType != null && authTokenType.equals(Authenticator.FB_KEY_TOKEN)) {
        result.putExtra(AccountManager.KEY_AUTHTOKEN, key);
    } else if (authTokenType != null && authTokenType.equals(Authenticator.FB_UID_TOKEN)) {
        result.putExtra(AccountManager.KEY_AUTHTOKEN, uid);
    } else {
        result.putExtra(AccountManager.KEY_AUTHTOKEN, accessToken);
    }

    setAccountAuthenticatorResult(result.getExtras());
    setResult(RESULT_OK, result);

    CalendarSyncAdapter.updateSync(this);

    Toast.makeText(this, R.string.auth_account_creation_success_toast, Toast.LENGTH_SHORT)
            .show();
    finish();
}
 
開發者ID:danvratil,項目名稱:FBEventSync,代碼行數:48,代碼來源:AuthenticatorActivity.java

示例11: createSyncAccount

import android.content.ContentResolver; //導入方法依賴的package包/類
private Account createSyncAccount() {
    AccountManager am = AccountManager.get(this);
    Account[] accounts;

    try {
        accounts = am.getAccountsByType("de.slg.leoapp");
    } catch (SecurityException e) {
        accounts = new Account[0];
    }
    if (accounts.length > 0) {
        return accounts[0];
    }
    Account newAccount = new Account("default_account", "de.slg.leoapp");
    if (am.addAccountExplicitly(newAccount, "pass1", null)) {
        ContentResolver.setIsSyncable(newAccount, "de.slg.leoapp", 1);
        ContentResolver.setSyncAutomatically(newAccount, "de.slg.leoapp", true);
    } else {
        newAccount = null;
    }

    return newAccount;
}
 
開發者ID:LCA311,項目名稱:leoapp-sources,代碼行數:23,代碼來源:Start.java

示例12: getOrCreateAccount

import android.content.ContentResolver; //導入方法依賴的package包/類
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
  AccountManager accountManager = AccountManager.get(context);
  Account[]      accounts       = accountManager.getAccountsByType("id.kita.pesan.secure");

  Optional<AccountHolder> account;

  if (accounts.length == 0) account = createAccount(context);
  else                      account = Optional.of(new AccountHolder(accounts[0], false));

  if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
    ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
  }

  return account;
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:16,代碼來源:DirectoryHelper.java


注:本文中的android.content.ContentResolver.setSyncAutomatically方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。