本文整理汇总了Java中com.google.samples.apps.iosched.util.AccountUtils.getGcmKey方法的典型用法代码示例。如果您正苦于以下问题:Java AccountUtils.getGcmKey方法的具体用法?Java AccountUtils.getGcmKey怎么用?Java AccountUtils.getGcmKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.samples.apps.iosched.util.AccountUtils
的用法示例。
在下文中一共展示了AccountUtils.getGcmKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notifyUserDataChanged
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
* Request user data sync.
*
* @param context Current context
*/
public static void notifyUserDataChanged(final Context context) {
if (!checkGcmEnabled()) {
return;
}
LOGI(TAG, "Notifying GCM that user data changed");
String serverUrl = BuildConfig.GCM_SERVER_URL + "/send/self/sync_user";
try {
String gcmKey = AccountUtils.getGcmKey(context, AccountUtils.getActiveAccountName(context));
if (gcmKey != null) {
post(serverUrl, new HashMap<String, String>(), gcmKey);
}
} catch (IOException e) {
LOGE(TAG, "Unable to notify GCM about user data change", e);
}
}
示例2: notifyUserDataChanged
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
* Request user data sync.
*
* @param context Current context
*/
public static void notifyUserDataChanged(final Context context) {
if (!checkGcmEnabled()) {
return;
}
LOGI(TAG, "Notifying GCM that user data changed");
String serverUrl = Config.GCM_SERVER_URL + "/send/self/sync_user";
try {
String gcmKey = AccountUtils.getGcmKey(context, AccountUtils.getActiveAccountName(context));
if (gcmKey != null) {
post(serverUrl, new HashMap<String, String>(), gcmKey);
}
} catch (IOException e) {
LOGE(TAG, "Unable to notify GCM about user data change", e);
}
}
示例3: registerGCMClient
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
* Registers device on the GCM server, if necessary.
* <p/>
* This check is done in BaseActivity (as opposed to {@link AppApplication}) in order to make sure
* that this is always run after a user switch.
* <p/>
* As a future improvement, this code could be manually invoked by the app after a user
* switch occurs, which would allow moving this code to {@link AppApplication}.
*/
private void registerGCMClient() {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (TextUtils.isEmpty(regId)) {
// Automatically registers application on startup.
GCMRegistrar.register(this, BuildConfig.GCM_SENDER_ID);
} else {
// Get the correct GCM key for the user. GCM key is a somewhat non-standard
// approach we use in this app. For more about this, check GCM.TXT.
final String gcmKey = AccountUtils.hasActiveAccount(this) ?
AccountUtils.getGcmKey(this, AccountUtils.getActiveAccountName(this)) : null;
// Device is already registered on GCM, needs to check if it is
// registered on our server as well.
if (ServerUtilities.isRegisteredOnServer(this, gcmKey)) {
// Skips registration.
LOGI(TAG, "Already registered on the GCM server with right GCM key.");
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
mGCMRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
LOGI(TAG, "Registering on the GCM server with GCM key: "
+ AccountUtils.sanitizeGcmKey(gcmKey));
boolean registered = ServerUtilities.register(BaseActivity.this,
regId, gcmKey);
// At this point all attempts to register with the app
// server failed, so we need to unregister the device
// from GCM - the app will try to register again when
// it is restarted. Note that GCM will send an
// unregistered callback upon completion, but
// GCMIntentService.onUnregistered() will ignore it.
if (!registered) {
LOGI(TAG, "GCM registration failed.");
GCMRegistrar.unregister(BaseActivity.this);
} else {
LOGI(TAG, "GCM registration successful.");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mGCMRegisterTask = null;
}
};
mGCMRegisterTask.execute(null, null, null);
}
}
}
示例4: registerGCMClient
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/** Registers device on the GCM server, if necessary. */
private void registerGCMClient() {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (TextUtils.isEmpty(regId)) {
// Automatically registers application on startup.
GCMRegistrar.register(this, Config.GCM_SENDER_ID);
} else {
// Get the correct GCM key for the user. GCM key is a somewhat non-standard
// approach we use in this app. For more about this, check GCM.TXT.
final String gcmKey = AccountUtils.hasActiveAccount(this) ?
AccountUtils.getGcmKey(this, AccountUtils.getActiveAccountName(this)) : null;
// Device is already registered on GCM, needs to check if it is
// registered on our server as well.
if (ServerUtilities.isRegisteredOnServer(this, gcmKey)) {
// Skips registration.
LOGI(TAG, "Already registered on the GCM server with right GCM key.");
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
mGCMRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
LOGI(TAG, "Registering on the GCM server with GCM key: "
+ AccountUtils.sanitizeGcmKey(gcmKey));
boolean registered = ServerUtilities.register(BaseActivity.this,
regId, gcmKey);
// At this point all attempts to register with the app
// server failed, so we need to unregister the device
// from GCM - the app will try to register again when
// it is restarted. Note that GCM will send an
// unregistered callback upon completion, but
// GCMIntentService.onUnregistered() will ignore it.
if (!registered) {
LOGI(TAG, "GCM registration failed.");
GCMRegistrar.unregister(BaseActivity.this);
} else {
LOGI(TAG, "GCM registration successful.");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mGCMRegisterTask = null;
}
};
mGCMRegisterTask.execute(null, null, null);
}
}
}
示例5: 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;
}