當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。