本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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...");
}
}
示例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);
}
示例6: initSyncAdapter
import android.content.ContentResolver; //导入方法依赖的package包/类
private void initSyncAdapter() {
ContentResolver.addPeriodicSync(
createSyncAccount(),
"de.slg.leoapp",
Bundle.EMPTY,
10*60);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}