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


Java ContentResolver.requestSync方法代码示例

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


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

示例4: setSyncActivated

import android.content.ContentResolver; //导入方法依赖的package包/类
public void setSyncActivated(boolean enabled) {
	
       ContentResolver.setMasterSyncAutomatically(enabled);
       
       if (enabled) {
       	SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
       	AccountManager accmgr = AccountManager.get(mContext);
       	for (SyncAdapterType type : types) {
       		
       		Account[] accounts = accmgr.getAccountsByType(type.accountType);
       		for (Account account : accounts) {
       			
       			if (Constants.DEBUG) {
       				Log.d(TAG, "synching account, name:" + account.name  + ", type: " + account.type);
       			}
       			
       			enabled = ContentResolver.getSyncAutomatically(account, type.authority);
       			if (enabled) {
       				// trigger update for next account
       				ContentResolver.requestSync(account, type.authority, new Bundle());
       			}
       		}
       	}
       }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:26,代码来源:SyncControl20.java

示例5: onReceive

import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    String accountName = AccountUtils.getActiveAccountName(context);
    if (TextUtils.isEmpty(accountName)) {
        return;
    }
    Account account = AccountUtils.getActiveAccount(context);
    if (account != null) {
        if (intent.getBooleanExtra(EXTRA_USER_DATA_SYNC_ONLY, false) ) {
            // this is a request to sync user data only, so do a manual sync right now
            // with the userDataOnly == true.
            SyncHelper.requestManualSync(account, true);
        } else {
            // this is a request to sync everything
            ContentResolver.requestSync(account, ScheduleContract.CONTENT_AUTHORITY, new Bundle());
        }
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:19,代码来源:TriggerSyncReceiver.java

示例6: requestSync

import android.content.ContentResolver; //导入方法依赖的package包/类
public static void requestSync(Context context, Bundle previousExtras) {
    int attempt = previousExtras.getInt(BUNDLE_ATTEMPT, 0);

    if (attempt > MAX_REPEATED_SYNC_ATTEMPT) {
        if (BuildConfig.DEBUG) {
            Log.d(LOG_TAG, String.format("" +
                    "Repeated sync is requested: attempt %s: denied", attempt));
        }

        return;
    }

    Bundle newExtras = new Bundle();
    newExtras.putInt(BUNDLE_ATTEMPT, attempt + 1);

    if (BuildConfig.DEBUG) {
        Log.d(LOG_TAG, String.format("Repeated sync is requested: attempt %s", attempt));
    }

    ContentResolver.requestSync(makeAccount(context), GigApplication.getSyncAuthority(), newExtras);
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:22,代码来源:SyncManager.java

示例7: syncImmediately

import android.content.ContentResolver; //导入方法依赖的package包/类
public static void syncImmediately(Context context) {

        Bundle bundle = new Bundle();
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        ContentResolver.requestSync(getSyncAccount(context),
                AUTHORITY, bundle);
        System.out.println("xxxx syncImmediately");
    }
 
开发者ID:jamesddube,项目名称:LaravelNewsApp,代码行数:10,代码来源:SyncAdapter.java

示例8: requestSync

import android.content.ContentResolver; //导入方法依赖的package包/类
static public void requestSync(Context context) {
    String accountType = context.getResources().getString(R.string.account_type);
    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.requestSync(account, CalendarContract.AUTHORITY, extras);
        logger.info(TAG, "Explicitly requested sync for account %s", account.name);
    }
}
 
开发者ID:danvratil,项目名称:FBEventSync,代码行数:12,代码来源:CalendarSyncAdapter.java

示例9: syncImmediately

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * Helper method to have the sync adapter sync immediately
 */
public static void syncImmediately(Context context, int syncInterval, int syncFlexTime) {
    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(getSyncAccount(context, syncInterval, syncFlexTime),
            context.getString(R.string.rnsb_content_authority), bundle);
}
 
开发者ID:ferrannp,项目名称:react-native-sync-adapter,代码行数:11,代码来源:SyncAdapter.java

示例10: syncImmediately

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * Helper method to have the sync adapter sync immediately
 * @param context The context used to access the account service
 */
public static void syncImmediately(Context context) {
    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(getSyncAccount(context),
            context.getString(R.string.content_authority), bundle);
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:12,代码来源:SunshineSyncAdapter.java

示例11: requestImmediateSync

import android.content.ContentResolver; //导入方法依赖的package包/类
public static void requestImmediateSync() {
    Bundle b = new Bundle();
    b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

    Account account = AccountService.getAccount();
    ContentResolver.requestSync(account, FuelUpContract.CONTENT_AUTHORITY, b);
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:9,代码来源:DriveSyncingUtils.java

示例12: onChange

import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
public void onChange(boolean selfChange, Uri uri) {
    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    ContentResolver.requestSync(
            AccountService.getAccount(),
            FuelUpContract.CONTENT_AUTHORITY,
            bundle);
    PreferencesUtils.setLastChange(context);
    Log.i(LOG_TAG, "sync adapter has been notified");
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:13,代码来源:SyncAdapterContentObserver.java

示例13: sync

import android.content.ContentResolver; //导入方法依赖的package包/类
public void sync(Bundle data) {
    AccountManager manager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    Account[] accounts = manager.getAccountsByType(context.getString(R.string.auth_type));
    if (accounts.length > 0) {
        Bundle settings = new Bundle();
        settings.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        settings.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
        settings.putString(SyncAdapter.KEY_SYNC_MODEL, model.getModelName());
        if (data != null)
            settings.putAll(data);
        ContentResolver.requestSync(accounts[0], model.getAuthority(), settings);
    }
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:14,代码来源:OSyncUtils.java

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

示例15: forceRefreshAll

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * Helper method to trigger an immediate sync ("refresh").
 * <p>
 * <p>This should only be used when we need to preempt the normal sync schedule. Typically, this
 * means the user has pressed the "refresh" button.
 * <p>
 * Note that SYNC_EXTRAS_MANUAL will cause an immediate sync, without any optimization to
 * preserve battery life. If you know new data is available (perhaps via a GCM notification),
 * but the user is not actively waiting for that data, you should omit this flag; this will give
 * the OS additional freedom in scheduling your sync request.
 */
public static void forceRefreshAll(Context context) {
    Bundle bundle = new Bundle();
    // Disable sync backoff and ignore sync preferences.
    // In other words...perform sync NOW!
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    ContentResolver.requestSync(
            getAccount(context),        // Sync account
            CONTENT_AUTHORITY,          // Content authority
            bundle);         // Extras
}
 
开发者ID:jaydeepw,项目名称:simplest-sync-adapter,代码行数:23,代码来源:SyncUtils.java


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