当前位置: 首页>>代码示例>>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;未经允许,请勿转载。