当前位置: 首页>>代码示例>>Java>>正文


Java ContentResolver.addPeriodicSync方法代码示例

本文整理汇总了Java中android.content.ContentResolver.addPeriodicSync方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver.addPeriodicSync方法的具体用法?Java ContentResolver.addPeriodicSync怎么用?Java ContentResolver.addPeriodicSync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.ContentResolver的用法示例。


在下文中一共展示了ContentResolver.addPeriodicSync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configurePeriodicSync

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * Based on https://gist.github.com/udacityandroid/7230489fb8cb3f46afee
 */
private static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
    Account account = getSyncAccount(context, syncInterval, flexTime);
    String authority = context.getString(R.string.rnsb_content_authority);
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // We can enable inexact timers in our periodic sync (better for batter life)
        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);
    }
}
 
开发者ID:ferrannp,项目名称:react-native-sync-adapter,代码行数:20,代码来源:SyncAdapter.java

示例2: configurePeriodicSync

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * Helper method to schedule the sync adapter periodic execution
 */
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).
                setExtras(new Bundle()).build();
        ContentResolver.requestSync(request);
    } else {
        ContentResolver.addPeriodicSync(account,
                authority, new Bundle(), syncInterval);
    }
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:19,代码来源:SunshineSyncAdapter.java

示例3: 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

示例4: 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

示例5: configurePeriodicSync

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * Helper method to schedule the sync adapter periodic execution
 */
public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
    Account account = getSyncAccount(context);
    String authority = AUTHORITY;

    ContentResolver.addPeriodicSync(account,authority,new Bundle(), syncInterval);
}
 
开发者ID:jamesddube,项目名称:LaravelNewsApp,代码行数:10,代码来源:SyncAdapter.java

示例6: initSyncAdapter

import android.content.ContentResolver; //导入方法依赖的package包/类
private void initSyncAdapter() {
    ContentResolver.addPeriodicSync(
            createSyncAccount(),
            "de.slg.leoapp",
            Bundle.EMPTY,
            10*60);
}
 
开发者ID:LCA311,项目名称:leoapp-sources,代码行数:8,代码来源:Start.java

示例7: configurePeriodicSync

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * Helper method to schedule the sync adapter periodic execution
 */
public static void configurePeriodicSync(Context context, long syncInterval, long 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).
                setExtras(new Bundle()).build();
        ContentResolver.requestSync(request);
    } else {
        ContentResolver.addPeriodicSync(account,
                authority, new Bundle(), syncInterval);
    }
}
 
开发者ID:graviton57,项目名称:TVGuide,代码行数:19,代码来源:TvGuideSyncAdapter.java

示例8: 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

示例9: updateSync

import android.content.ContentResolver; //导入方法依赖的package包/类
static public void updateSync(Context context) {
    String accountType = context.getResources().getString(R.string.account_type);

    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    String syncFreq = pref.getString(context.getResources().getString(R.string.pref_sync_frequency),
                                     context.getResources().getString(R.string.pref_sync_frequency_default_value));
    assert(syncFreq != null);
    int syncInterval = Integer.parseInt(syncFreq);

    Logger logger = Logger.getInstance(context);

    for (Account account : AccountManager.get(context).getAccountsByType(accountType)) {
        Bundle extras = new Bundle();
        extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL,true);
        extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

        ContentResolver.cancelSync(account, CalendarContract.AUTHORITY);
        if (syncInterval == 0) {
            continue;
        }

        // Schedule periodic sync based on current configuration
        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, syncInterval / 3)
                    .setSyncAdapter(account, CalendarContract.AUTHORITY)
                    .setExtras(new Bundle()).build();
            ContentResolver.requestSync(request);
            logger.info(TAG, "Scheduled periodic sync for account %s using requestSync, interval: %d",
                        account.name, syncInterval);
        } else {
            ContentResolver.addPeriodicSync(account, CalendarContract.AUTHORITY, new Bundle(), syncInterval);
            logger.info(TAG, "Scheduled periodic sync for account %s using addPeriodicSync, interval: %d",
                        account.name, syncInterval);
        }
    }
}
 
开发者ID:danvratil,项目名称:FBEventSync,代码行数:39,代码来源:CalendarSyncAdapter.java


注:本文中的android.content.ContentResolver.addPeriodicSync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。