GCM有2种不同regIds两次注册 [英] GCM registering twice with 2 different regIds

查看:207
本文介绍了GCM有2种不同regIds两次注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我有这个code注册到GCM服务:

in my app I have this code to register to the GCM service:

protected void registerToGcm() {
    GCMRegistrar.checkDevice(mContext);
    GCMRegistrar.checkManifest(mContext);
    String regId = GCMRegistrar.getRegistrationId(mContext);
    if ("".equals(regId)) {
        GCMRegistrar.register(mContext, GCMIntentService.SENDER_ID);
    } else {
        registerToServer(regId);
    }
}

GCMIntentService.Java

public static final String SENDER_ID = "1111111111";
@Override
protected void onRegistered(Context context, String regId) {
    Log.d(TAG, "Registered to GCM with regId: " + regId);
    Server.registerToServer(regId);
}

当我运行这个code,我在我的设备与注册两次服务器看到2个不同的 regIds ,并在服务器发送一个推动下,设备接收2个消息。

when I run this code, I see in the server that my device is registering twice with 2 different regIds, and when the server sends a push, the device receives 2 messages.

这是很正常的事情?有没有一种方法,以确保只有一个 REGID

is this a normal thing? is there a way to ensure only one regId?

推荐答案

你有什么需要检查时,你要注册为

What do you need to check when you want to register is

GCMRegistrar.checkDevice(getApplicationContext());
GCMRegistrar.checkManifest(getApplicationContext());

deviceToken = GCMRegistrar.getRegistrationId(getApplicationContext());

if (printLog == true)
    Log.i("Home", "Registration id =====  " + deviceToken);
if (deviceToken.equals("")) {
    GCMRegistrar.register(getApplicationContext(), SENDER_ID);
} else {
    if (printLog == true)
        Log.v("Home", "Device Already registered");
}

这篇关于GCM有2种不同regIds两次注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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