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


Java AccountUtils.setGcmKey方法代码示例

本文整理汇总了Java中com.google.samples.apps.iosched.util.AccountUtils.setGcmKey方法的典型用法代码示例。如果您正苦于以下问题:Java AccountUtils.setGcmKey方法的具体用法?Java AccountUtils.setGcmKey怎么用?Java AccountUtils.setGcmKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.samples.apps.iosched.util.AccountUtils的用法示例。


在下文中一共展示了AccountUtils.setGcmKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: syncImpl

import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
 * Syncs the preferences file with an appdata preferences file.
 *
 * Synchronization steps:
 * 1. If there are local changes, sync the latest local version with remote
 *    and ignore merge conflicts. The last write wins.
 * 2. If there are no local changes, fetch the latest remote version. If
 *    it includes changes, notify that preferences have changed.
 */
protected boolean syncImpl(List<UserAction> actions, boolean hasPendingLocalData) {
    try {
        LOGD(TAG, "Now syncing user data.");
        Set<String> remote = UserDataHelper.fromString(fetchRemote());
        Set<String> local = UserDataHelper.getSessionIDs(actions);

        String remoteGcmKey = extractGcmKey(remote);
        String localGcmKey = AccountUtils.getGcmKey(mContext, mAccountName);
        LOGD(TAG, "Local GCM key: " + AccountUtils.sanitizeGcmKey(localGcmKey));
        LOGD(TAG, "Remote GCM key: " + (remoteGcmKey == null ? "(null)"
                : AccountUtils.sanitizeGcmKey(remoteGcmKey)));

        // if the remote data came with a GCM key, it should override ours
        if (!TextUtils.isEmpty(remoteGcmKey)) {
            if (remoteGcmKey.equals(localGcmKey)) {
                LOGD(TAG, "Remote GCM key is the same as local, so no action necessary.");
            } else {
                LOGD(TAG, "Remote GCM key is different from local. OVERRIDING local.");
                localGcmKey = remoteGcmKey;
                AccountUtils.setGcmKey(mContext, mAccountName, localGcmKey);
            }
        }

        // If remote data is the same as local, and the remote end already has a GCM key,
        // there is nothing we need to do.
        if (remote.equals(local) && !TextUtils.isEmpty(remoteGcmKey)) {
            LOGD(TAG, "Update is not needed (local is same as remote, and remote has key)");
            return false;
        }

        Set<String> merged;
        if (hasPendingLocalData || TextUtils.isEmpty(remoteGcmKey)) {
            // merge local dirty actions into remote content
            if (hasPendingLocalData) {
                LOGD(TAG, "Has pending local data, merging.");
                merged = mergeDirtyActions(actions, remote);
            } else {
                LOGD(TAG, "No pending local data, just updating remote GCM key.");
                merged = remote;
            }
            // add the GCM key special item
            merged.add(GCM_KEY_PREFIX + localGcmKey);
            // save to remote
            LOGD(TAG, "Sending user data to Drive, gcm key "
                    + AccountUtils.sanitizeGcmKey(localGcmKey));
            new UpdateFileDriveTask(getDriveService()).execute(
                    UserDataHelper.toSessionsString(merged));
        } else {
            merged = remote;
        }

        UserDataHelper.setLocalStarredSessions(mContext, merged, mAccountName);
        return true;
    } catch (IOException e) {
        handleException(e);
    }
    return false;
}
 
开发者ID:gdg-bh,项目名称:AppDevFestSudeste2015,代码行数:68,代码来源:HTTPUserDataSyncHelper.java


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