本文整理汇总了Java中com.google.samples.apps.iosched.Config.GCM_SERVER_URL属性的典型用法代码示例。如果您正苦于以下问题:Java Config.GCM_SERVER_URL属性的具体用法?Java Config.GCM_SERVER_URL怎么用?Java Config.GCM_SERVER_URL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.samples.apps.iosched.Config
的用法示例。
在下文中一共展示了Config.GCM_SERVER_URL属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unregister
/**
* Unregister this account/device pair within the server.
*
* @param context Current context
* @param gcmId The GCM registration ID for this device
*/
static void unregister(final Context context, final String gcmId) {
if (!checkGcmEnabled()) {
return;
}
LOGI(TAG, "unregistering device (gcmId = " + gcmId + ")");
String serverUrl = Config.GCM_SERVER_URL + "/unregister";
Map<String, String> params = new HashMap<String, String>();
params.put("gcm_id", gcmId);
try {
post(serverUrl, params, Config.GCM_API_KEY);
setRegisteredOnServer(context, false, gcmId, null);
} catch (IOException e) {
// At this point the device is unregistered from GCM, but still
// registered in the server.
// We could try to unregister again, but it is not necessary:
// if the server tries to send a message to the device, it will get
// a "NotRegistered" error message and should unregister the device.
LOGD(TAG, "Unable to unregister from application server", e);
} finally {
// Regardless of server success, clear local preferences
setRegisteredOnServer(context, false, null, null);
}
}
示例2: notifyUserDataChanged
/**
* 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: register
/**
* Register this account/device pair within the server.
*
* @param context Current context
* @param gcmId The GCM registration ID for this device
* @param gcmKey The GCM key with which to register.
* @return whether the registration succeeded or not.
*/
public static boolean register(final Context context, final String gcmId, final String gcmKey) {
if (!checkGcmEnabled()) {
return false;
}
LOGI(TAG, "registering device (gcm_id = " + gcmId + ")");
String serverUrl = Config.GCM_SERVER_URL + "/register";
LOGI(TAG, "registering on GCM with GCM key: " + AccountUtils.sanitizeGcmKey(gcmKey));
Map<String, String> params = new HashMap<String, String>();
params.put("gcm_id", gcmId);
params.put("gcm_key", gcmKey);
long backoff = BACKOFF_MILLI_SECONDS + sRandom.nextInt(1000);
// Once GCM returns a registration id, we need to register it in the
// demo server. As the server might be down, we will retry it a couple
// times.
for (int i = 1; i <= MAX_ATTEMPTS; i++) {
LOGV(TAG, "Attempt #" + i + " to register");
try {
post(serverUrl, params, Config.GCM_API_KEY);
setRegisteredOnServer(context, true, gcmId, gcmKey);
return true;
} catch (IOException e) {
// Here we are simplifying and retrying on any error; in a real
// application, it should retry only on unrecoverable errors
// (like HTTP error code 503).
LOGE(TAG, "Failed to register on attempt " + i, e);
if (i == MAX_ATTEMPTS) {
break;
}
try {
LOGV(TAG, "Sleeping for " + backoff + " ms before retry");
Thread.sleep(backoff);
} catch (InterruptedException e1) {
// Activity finished before we complete - exit.
LOGD(TAG, "Thread interrupted: abort remaining retries!");
Thread.currentThread().interrupt();
return false;
}
// increase backoff exponentially
backoff *= 2;
}
}
return false;
}