本文整理汇总了Java中android.content.SyncRequest类的典型用法代码示例。如果您正苦于以下问题:Java SyncRequest类的具体用法?Java SyncRequest怎么用?Java SyncRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SyncRequest类属于android.content包,在下文中一共展示了SyncRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的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);
}
}
示例2: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的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);
}
}
示例3: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的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.contentauthority);
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);
}
}
示例4: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的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.sync_provider_authority);
if (syncInterval == -1) {
ContentResolver.setSyncAutomatically(account, context.getString(R.string.sync_provider_authority), false);
} else {
ContentResolver.setSyncAutomatically(account, context.getString(R.string.sync_provider_authority), true);
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);
}
}
}
示例5: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的package包/类
private static void configurePeriodicSync(Context context, int syncInterval, int syncFlextime) {
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
try {
SyncRequest request = new SyncRequest.Builder().
syncPeriodic(syncInterval, syncFlextime).
setSyncAdapter(account, authority).build();
ContentResolver.requestSync(request);
} catch (Exception e) {
}
} else {
ContentResolver.addPeriodicSync(account,
authority, new Bundle(), syncInterval);
}
}
示例6: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的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);
}
}
示例7: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的package包/类
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);
ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
} else {
ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
}
}
示例8: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的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);
}
}
示例9: setPeriodicSync
import android.content.SyncRequest; //导入依赖的package包/类
/**
* Set synchronisation everyday with 4 hours flexible time
* @param context
* @param account
*/
private static void setPeriodicSync(Context context, Account account) {
String authority = context.getResources().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(SYNC_INTERVAL, SYNC_FLEXTIME).
setSyncAdapter(account, authority).
setExtras(Bundle.EMPTY).build();
ContentResolver.requestSync(request);
} else {
ContentResolver.addPeriodicSync(
account,
authority,
Bundle.EMPTY,
SYNC_INTERVAL);
}
ContentResolver.setSyncAutomatically(account, context.getString(R.string.content_authority), true);
}
示例10: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的package包/类
/**
* Helper method to schedule periodic execution of a sync adapter.
* flexTime is only used on KitKat and newer devices.
*/
public static void configurePeriodicSync(Account account, String authority,
int syncInterval, int flexTime) {
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(Bundle.EMPTY)
.build();
ContentResolver.requestSync(request);
} else {
ContentResolver.addPeriodicSync(account, authority, Bundle.EMPTY, syncInterval);
}
}
示例11: syncAsUser
import android.content.SyncRequest; //导入依赖的package包/类
public void syncAsUser(SyncRequest request, int userId) {
Account account = mirror.android.content.SyncRequest.mAccountToSync.get(request);
String authority = mirror.android.content.SyncRequest.mAuthority.get(request);
Bundle extras = mirror.android.content.SyncRequest.mExtras.get(request);
boolean isPeriodic = mirror.android.content.SyncRequest.mIsPeriodic.get(request);
long syncRunTimeSecs = mirror.android.content.SyncRequest.mSyncRunTimeSecs.get(request);
if (!isAccountExist(userId, account, authority)) {
return;
}
VSyncRecord.SyncRecordKey key = new VSyncRecord.SyncRecordKey(account, authority);
VSyncRecord.SyncExtras syncExtras = new VSyncRecord.SyncExtras(extras);
int isSyncable = getIsSyncableAsUser(account, authority, userId);
synchronized (mRecords) {
Map<VSyncRecord.SyncRecordKey, VSyncRecord> map = mRecords.get(userId);
if (map == null) {
map = new HashMap<>();
mRecords.put(userId, map);
}
VSyncRecord record = map.get(key);
if (record == null) {
record = new VSyncRecord(userId, account, authority);
map.put(key, record);
}
if (isSyncable < 0) {
// Initialisation sync.
Bundle newExtras = new Bundle();
newExtras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true);
record.extras.add(new VSyncRecord.SyncExtras(newExtras));
}
if (isPeriodic) {
VSyncRecord.PeriodicSyncConfig periodicSyncConfig = new VSyncRecord.PeriodicSyncConfig(syncRunTimeSecs);
record.configs.put(syncExtras, periodicSyncConfig);
} else {
record.extras.add(syncExtras);
}
}
}
示例12: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的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);
}
}
示例13: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的package包/类
/**
* Helper method to schedule the sync adapter periodic execution
*/
private static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
SyncRequest request = new SyncRequest.Builder().
syncPeriodic(syncInterval, flexTime).
setSyncAdapter(mAccount, context.getString(R.string.sync_authority)).
setExtras(new Bundle()).build();
ContentResolver.requestSync(request);
} else {
ContentResolver.addPeriodicSync(mAccount,
context.getString(R.string.sync_authority), new Bundle(), syncInterval);
}
}
示例14: startSynchronization
import android.content.SyncRequest; //导入依赖的package包/类
protected void startSynchronization() {
Log_OC.d(TAG, "Got to start sync");
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
Log_OC.d(TAG, "Canceling all syncs for " + MainApp.getAuthority());
ContentResolver.cancelSync(null, MainApp.getAuthority());
// cancel the current synchronizations of any ownCloud account
Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
MainApp.getAuthority());
ContentResolver.requestSync(
getAccount(),
MainApp.getAuthority(), bundle);
} else {
Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
MainApp.getAuthority() + " with new API");
SyncRequest.Builder builder = new SyncRequest.Builder();
builder.setSyncAdapter(getAccount(), MainApp.getAuthority());
builder.setExpedited(true);
builder.setManual(true);
builder.syncOnce();
// Fix bug in Android Lollipop when you click on refresh the whole account
Bundle extras = new Bundle();
builder.setExtras(extras);
SyncRequest request = builder.build();
ContentResolver.requestSync(request);
}
}
示例15: configurePeriodicSync
import android.content.SyncRequest; //导入依赖的package包/类
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);
}
}