相应的新的GCM GCMRegistrar.isRegistered() [英] Corresponding GCMRegistrar.isRegistered() in new GCM

查看:104
本文介绍了相应的新的GCM GCMRegistrar.isRegistered()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用实现GCM新的 Google云端通讯API

I am trying to implement GCM using the new GoogleCloudMessaging API.

我要检查设备是否注册在云上,这是$ P $使用pviously检查 GCMRegistrar.isRegistered()

I want to check whether the device is registered on the cloud, which was previously checked using GCMRegistrar.isRegistered().

有什么办法,我可以使用新的API实现这个检查?结果
编辑:我知道我能救设好注册编号在我的应用程序,但我想知道我的设备的状态对云 - 无论是注册与否

Is there any way I can achieve this check using the new API?
I know I can save the registeration Id in my app, but I want to know the status of my device on the cloud - whether it is registered or not.

推荐答案

的去precated GCMRegistrar 是只是存储在RegistrationID本地的一个辅助客户端类设备。 GCMRegistrar.isRegistered()从来没有所谓的GCM服务器以发现设备注册(因为没有这样的API)。它只是检查是否previously收到RegistrationID存储在本地设备上的特定应用(和无效的存储RegistrationId在某些场合,如当应用程序版本变更)。

The deprecated GCMRegistrar was just a helper client class that stored the RegistrationID locally on the device. GCMRegistrar.isRegistered() never called the GCM server to find if the device is registered (since there is no such API). It just checked if a previously received RegistrationID is locally stored on the device for a specific app (and invalidated the stored RegistrationId on some occassions, such as when the app version changes).

在事实上,你可以看到GCMRegistrar的code <一个href=\"http://$c$c.google.com/p/gcm/source/browse/gcm-client/src/com/google/android/gcm/GCMRegistrar.java?r=87275a7eaab265c60b17f178b0c5cdd2983dc686\"相对=nofollow>这里:

In fact, you can see the code of GCMRegistrar here:

/**
 * Gets the current registration id for application on GCM service.
 * <p>
 * If result is empty, the registration has failed.
 *
 * @return registration id, or empty string if the registration is not
 *         complete.
 */
public static String getRegistrationId(Context context) {
    final SharedPreferences prefs = getGCMPreferences(context);
    String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    // check if app was updated; if so, it must clear registration id to
    // avoid a race condition if GCM sends a message
    int oldVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    int newVersion = getAppVersion(context);
    if (oldVersion != Integer.MIN_VALUE && oldVersion != newVersion) {
        Log.v(TAG, "App version changed from " + oldVersion + " to " +
                newVersion + "; resetting registration id");
        clearRegistrationId(context);
        registrationId = "";
    }
    return registrationId;
}

/**
 * Checks whether the application was successfully registered on GCM
 * service.
 */
public static boolean isRegistered(Context context) {
    return getRegistrationId(context).length() > 0;
}

因此​​,如果您存储的注册ID在你的应用程序,你会实现,当你使用 GCMRegistrar 你有完全相同的功能。只有这样,才能知道肯定,该设备已注册或没有注册到GCM是调用客户端应用程序 GoogleCloudMessaging.register GoogleCloudMessaging.unregister

Therefore, if you store the registration ID in your app, you would achieve the exact same functionality you had when you used GCMRegistrar. The only way to know for sure in the client app that the device is registered or not registered to GCM is to call GoogleCloudMessaging.register or GoogleCloudMessaging.unregister.

这篇关于相应的新的GCM GCMRegistrar.isRegistered()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆