本文整理汇总了Java中android.content.ContentResolver.setIsSyncable方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver.setIsSyncable方法的具体用法?Java ContentResolver.setIsSyncable怎么用?Java ContentResolver.setIsSyncable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentResolver
的用法示例。
在下文中一共展示了ContentResolver.setIsSyncable方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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...");
}
}
示例3: enableSyncGlobally
import android.content.ContentResolver; //导入方法依赖的package包/类
public static void enableSyncGlobally(Context context) {
Account genericAccount = AccountService.getAccount();
AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
List<Account> accounts = Arrays.asList(accountManager.getAccountsByType(AccountService.ACCOUNT_TYPE));
if(accounts.isEmpty()) {
Log.e(LOG_TAG, "Generic sync account must be added but it should have been already done when first running application.");
accountManager.addAccountExplicitly(genericAccount, null, null);
}
ContentResolver.setIsSyncable(genericAccount, FuelUpContract.CONTENT_AUTHORITY, 1);
}
示例4: disableSync
import android.content.ContentResolver; //导入方法依赖的package包/类
public static void disableSync(Context context) {
PreferencesUtils.remove(context, PreferencesUtils.BACKUP_FRAGMENT_ACCOUNT_IMPORT_ASKED,
PreferencesUtils.BACKUP_FRAGMENT_ACCOUNT_NAME);
Account genericAccount = AccountService.getAccount();
ContentResolver.setIsSyncable(genericAccount, FuelUpContract.CONTENT_AUTHORITY, 0);
Log.i(LOG_TAG, "Syncing is now disabled.");
}
示例5: 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);
}
}
示例6: 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();
}
示例7: onPerformSync
import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE)) {
Account signedInAccount = ChromeSigninController.get(getContext()).getSignedInUser();
if (account.equals(signedInAccount)) {
ContentResolver.setIsSyncable(account, authority, 1);
} else {
ContentResolver.setIsSyncable(account, authority, 0);
}
return;
}
PendingInvalidation invalidation = new PendingInvalidation(extras);
DelayedInvalidationsController controller = DelayedInvalidationsController.getInstance();
if (!controller.shouldNotifyInvalidation(extras)) {
controller.addPendingInvalidation(getContext(), account.name, invalidation);
return;
}
// Browser startup is asynchronous, so we will need to wait for startup to finish.
Semaphore semaphore = new Semaphore(0);
// Configure the BrowserParts with all the data it needs.
BrowserParts parts =
getBrowserParts(mApplication, account.name, invalidation, syncResult, semaphore);
startBrowserProcess(parts, syncResult, semaphore);
try {
// This code is only synchronously calling a single native method
// to trigger and asynchronous sync cycle, so 5 minutes is generous.
if (!semaphore.tryAcquire(5, TimeUnit.MINUTES)) {
Log.w(TAG, "Sync request timed out!");
syncResult.stats.numIoExceptions++;
}
} catch (InterruptedException e) {
Log.w(TAG, "Got InterruptedException when trying to request an invalidation.", e);
// Using numIoExceptions so Android will treat this as a soft error.
syncResult.stats.numIoExceptions++;
}
}
示例8: 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;
}
示例9: disableSync
import android.content.ContentResolver; //导入方法依赖的package包/类
public static void disableSync(Context context) {
Account account = makeAccount(context);
ContentResolver.cancelSync(account, GigApplication.getSyncAuthority());
ContentResolver.setIsSyncable(account, GigApplication.getSyncAuthority(), 0);
}
示例10: createAccount
import android.content.ContentResolver; //导入方法依赖的package包/类
private static Optional<AccountHolder> createAccount(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account account = new Account(context.getString(R.string.app_name), "id.kita.pesan.secure");
if (accountManager.addAccountExplicitly(account, null, null)) {
Log.w(TAG, "Created new account...");
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
return Optional.of(new AccountHolder(account, true));
} else {
Log.w(TAG, "Failed to create account!");
return Optional.absent();
}
}
示例11: createAccount
import android.content.ContentResolver; //导入方法依赖的package包/类
private static Optional<AccountHolder> createAccount(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account account = new Account(context.getString(R.string.app_name), "im.cable.cableim");
if (accountManager.addAccountExplicitly(account, null, null)) {
Log.w(TAG, "Created new account...");
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
return Optional.of(new AccountHolder(account, true));
} else {
Log.w(TAG, "Failed to create account!");
return Optional.absent();
}
}