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


Java Config.GCM_SERVER_URL属性代码示例

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

示例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);
    }
}
 
开发者ID:gdg-bh,项目名称:AppDevFestSudeste2015,代码行数:21,代码来源:ServerUtilities.java

示例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;
}
 
开发者ID:gdg-bh,项目名称:AppDevFestSudeste2015,代码行数:53,代码来源:ServerUtilities.java


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