当前位置: 首页>>代码示例>>Java>>正文


Java ContentResolver.setIsSyncable方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:21,代码来源:SyncManager.java

示例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...");
    }
}
 
开发者ID:jaydeepw,项目名称:simplest-sync-adapter,代码行数:28,代码来源:SyncUtils.java

示例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);
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:14,代码来源:DriveSyncingUtils.java

示例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.");
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:9,代码来源:DriveSyncingUtils.java

示例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);
    }
}
 
开发者ID:6thsolution,项目名称:EasyAppleSyncAdapter,代码行数:16,代码来源:MainActivity.java

示例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();
}
 
开发者ID:danvratil,项目名称:FBEventSync,代码行数:48,代码来源:AuthenticatorActivity.java

示例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++;
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:42,代码来源:ChromeBrowserSyncAdapter.java

示例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;
}
 
开发者ID:LCA311,项目名称:leoapp-sources,代码行数:23,代码来源:Start.java

示例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);
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:6,代码来源:SyncManager.java

示例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();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:14,代码来源:DirectoryHelper.java

示例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();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:14,代码来源:DirectoryHelper.java


注:本文中的android.content.ContentResolver.setIsSyncable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。