本文整理汇总了Java中android.content.ContentResolver.setSyncAutomatically方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver.setSyncAutomatically方法的具体用法?Java ContentResolver.setSyncAutomatically怎么用?Java ContentResolver.setSyncAutomatically使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentResolver
的用法示例。
在下文中一共展示了ContentResolver.setSyncAutomatically方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAccountCreated
import android.content.ContentResolver; //导入方法依赖的package包/类
private static void onAccountCreated(Account newAccount, Context context) {
/*
* Since we've created an account
*/
configurePeriodicSync(context, Prefs.getSyncInterval(), SYNC_FLEXTIME);
/*
* Without calling setSyncAutomatically, our periodic sync will not be enabled.
*/
ContentResolver.setSyncAutomatically(newAccount, AUTHORITY, true);
/*
* Finally, let's do a sync to get things started
*/
//syncImmediately(context);
}
示例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
+ ".");
}
}
示例3: onAccountCreated
import android.content.ContentResolver; //导入方法依赖的package包/类
private static void onAccountCreated(Account newAccount, Context context) {
/*
* Since we've created an account
*/
SunshineSyncAdapter.configurePeriodicSync(context, SYNC_INTERVAL, SYNC_FLEXTIME);
/*
* Without calling setSyncAutomatically, our periodic sync will not be enabled.
*/
ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true);
/*
* Finally, let's do a sync to get things started
*/
syncImmediately(context);
}
示例4: 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);
}
}
示例5: 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...");
}
}
示例6: onAccountCreated
import android.content.ContentResolver; //导入方法依赖的package包/类
private static void onAccountCreated(Account newAccount, Context context, int syncInterval, int syncFlexTime) {
// Since we've created an account
SyncAdapter.configurePeriodicSync(context, syncInterval, syncFlexTime);
// Without calling setSyncAutomatically, our periodic sync will not be enabled
ContentResolver.setSyncAutomatically(newAccount,
context.getString(R.string.rnsb_content_authority), true);
}
示例7: getOrCreateAccount
import android.content.ContentResolver; //导入方法依赖的package包/类
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType("im.cable.cableim");
Optional<AccountHolder> account;
if (accounts.length == 0) account = createAccount(context);
else account = Optional.of(new AccountHolder(accounts[0], false));
if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
}
return account;
}
示例8: onAccountCreated
import android.content.ContentResolver; //导入方法依赖的package包/类
private static void onAccountCreated(Account newAccount, Context context) {
final long interval = PreferencesHelper.getInstance()
.getSyncInterval(context.getString(R.string.pref_auto_sync_interval_key));
//Since we've created an account
TvGuideSyncAdapter.configurePeriodicSync(context, interval, interval / FLEX_DIVIDER);
//Without calling setSyncAutomatically, our periodic sync will not be enabled.
ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true);
//Finally, let's do a sync to get things started
syncImmediately(context);
}
示例9: 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);
}
}
示例10: createAccount
import android.content.ContentResolver; //导入方法依赖的package包/类
private void createAccount(String accessToken, String accountName) {
mLogger.debug("AUTH", "Creating account %s", accountName);
Intent intent = getIntent();
Account account = new Account(accountName, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
if (intent.getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false)) {
mAccountManager.addAccountExplicitly(account, null, null);
ContentResolver.setIsSyncable(account, CalendarContract.AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, CalendarContract.AUTHORITY, true);
}
Uri icalUri = Uri.parse(mBDayCalendar);
String key = icalUri.getQueryParameter("key");
String uid = icalUri.getQueryParameter("uid");
if (key == null || key.isEmpty() || uid == null || uid.isEmpty()) {
mLogger.error("AUTH", "Failed to retrieve iCal URL! The raw URL was " + mBDayCalendar);
Toast.makeText(this, getString(R.string.auth_calendar_uri_error_toast), Toast.LENGTH_SHORT)
.show();
finish();
return;
}
mAccountManager.setUserData(account, Authenticator.DATA_BDAY_URI, null); // clear the legacy storage
mAccountManager.setAuthToken(account, Authenticator.FB_OAUTH_TOKEN, accessToken);
mAccountManager.setAuthToken(account, Authenticator.FB_KEY_TOKEN, key);
mAccountManager.setAuthToken(account, Authenticator.FB_UID_TOKEN, uid);
Intent result = new Intent();
result.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName);
result.putExtra(AccountManager.KEY_ACCOUNT_TYPE, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
String authTokenType = intent.getStringExtra(AuthenticatorActivity.ARG_AUTH_TOKEN_TYPE);
if (authTokenType != null && authTokenType.equals(Authenticator.FB_KEY_TOKEN)) {
result.putExtra(AccountManager.KEY_AUTHTOKEN, key);
} else if (authTokenType != null && authTokenType.equals(Authenticator.FB_UID_TOKEN)) {
result.putExtra(AccountManager.KEY_AUTHTOKEN, uid);
} else {
result.putExtra(AccountManager.KEY_AUTHTOKEN, accessToken);
}
setAccountAuthenticatorResult(result.getExtras());
setResult(RESULT_OK, result);
CalendarSyncAdapter.updateSync(this);
Toast.makeText(this, R.string.auth_account_creation_success_toast, Toast.LENGTH_SHORT)
.show();
finish();
}
示例11: createSyncAccount
import android.content.ContentResolver; //导入方法依赖的package包/类
private Account createSyncAccount() {
AccountManager am = AccountManager.get(this);
Account[] accounts;
try {
accounts = am.getAccountsByType("de.slg.leoapp");
} catch (SecurityException e) {
accounts = new Account[0];
}
if (accounts.length > 0) {
return accounts[0];
}
Account newAccount = new Account("default_account", "de.slg.leoapp");
if (am.addAccountExplicitly(newAccount, "pass1", null)) {
ContentResolver.setIsSyncable(newAccount, "de.slg.leoapp", 1);
ContentResolver.setSyncAutomatically(newAccount, "de.slg.leoapp", true);
} else {
newAccount = null;
}
return newAccount;
}
示例12: getOrCreateAccount
import android.content.ContentResolver; //导入方法依赖的package包/类
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType("id.kita.pesan.secure");
Optional<AccountHolder> account;
if (accounts.length == 0) account = createAccount(context);
else account = Optional.of(new AccountHolder(accounts[0], false));
if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
}
return account;
}