本文整理汇总了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;
}