Android SDK中被从GCM在几个小时后NotRegistered错误 [英] Android SDK gets NotRegistered error from GCM after a few hours

查看:246
本文介绍了Android SDK中被从GCM在几个小时后NotRegistered错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

我写和Android SDK应该从SDK服务器端接收GCM推送消息。数小时后成功推送消息的发送,在GCM服务器返回一个 NotRegistered 错误:

  {
    multicast_id:6205350692941230304,
    成功:0,
    失败:1,
    canonical_ids:0,
    结果:
    [
        {
            错误:NotRegistered
        }
    ]
}
 

registrationId 在客户端没有改变,并且在服务器侧被与该令牌更新

我怎样才能修复 registrationId 的问题?是具有两个听众 - 一个在SDK中,一个在应用程序 - 问题

建筑

我的Andr​​oid SDK注册了一个GCM REGID 在初始化,并将该ID配套的SDK中的服务器。

在拥抱应用程序可能(通常)注册一个GCM自身 REGID 。另 REGID 可能是发送到拥抱的应用程序的服务器。

senderId SDK和应用程序是不同的。

实施

舱单

 <使用-权限的Andr​​oid:名称=com.google.android.c2dm.permission.RECEIVE/> ...

    <接收器
        机器人:名称=com.xxxx.xxxxx.xxxxx
        机器人:权限=com.google.android.c2dm.permission.SEND>
        <意向滤光器>
            <作用机器人:名称=com.google.android.c2dm.intent.RECEIVE/>
        &所述; /意图滤光器>
    < /接收器>
 

注册code

 保护字符串doInBackground(空... PARAMS){
    弦乐味精=;
    尝试 {
        如果(GCM == NULL){
            GCM = GoogleCloudMessaging.getInstance(mContext);
        }
        REGID = gcm.register(SENDER_ID);
        味精=注册设备,注册ID =+ REGID;
        storeRegistrationId(mContext,REGID);
        listener.onGCMRegisterFinish(REGID);
    }
    赶上(IOException异常前)
    {
        味精=错误:+ ex.getMessage();
    }
    返回味精;
}
 

这code得到 REGID 从GCM服务器并将其发送到我们​​的后台服务器。它是在SDK初始化过程中执行,而 REGID 的每一次发送的应用程序返回的背景。

注意

  • 取消注册()不叫,无论是从服务器或客户端
  • 在我的同时提高与注册ID敬酒每一次,这样我就可以验证它是客户端和服务器之间是相同的:
客户端

服务器端

  2015年8月2日12:31:22383信息 -  request_2145354041215926507
                        更新推令牌用户:XXXXXXXX,
                        push_token:... me1GttmSRipnW​​sCGVUueK7e0nk
 

解决方案

添加类别与您的包名的意图过滤器

 <接收器
        机器人:XXXXXNAME =
        机器人:权限=com.google.android.c2dm.permission.SEND>
        <意向滤光器>
            <  - !接收的实际消息。 - >
            <作用机器人:名称=com.google.android.c2dm.intent.RECEIVE/>
            <类机器人:名称=com.xxxx/>
        &所述; /意图滤光器>
    < /接收器>
 

The problem

I am writing and Android SDK which should receive GCM push messages from the SDK server side. After a few hours of successful push message sending, the GCM server returns an NotRegistered error:

{
    "multicast_id":6205350692941230304,
    "success":0,
    "failure":1,
    "canonical_ids":0,
    "results":
    [
        {
            "error":"NotRegistered"
        }
    ]
}

The registrationId at the client has not changed, and the server side is updated with that token.

How can I fix the registrationId problem? Is having two listeners - one in the SDK, one in the app - a problem?

Architecture

My Android SDK registers a GCM regId upon initialization, and sends that id to the server supporting the SDK.

The embracing app might (and usually do) register a GCM regId of its own. The other regId is probably sent to the embracing app's server.

The senderId of the SDK and app are different.

Implementation

Manifest

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> ...

    <receiver
        android:name="com.xxxx.xxxxx.xxxxx"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </receiver>

Registration code

protected String doInBackground(Void... params) {
    String msg = "";
    try {
        if (gcm == null) {
            gcm = GoogleCloudMessaging.getInstance(mContext);
        }
        regid = gcm.register(SENDER_ID);
        msg = "Device registered, registration ID=" + regid;
        storeRegistrationId(mContext, regid);
        listener.onGCMRegisterFinish(regid);
    } 
    catch (IOException ex) 
    {
        msg = "Error :" + ex.getMessage();
    }
    return msg;
}

This code gets the regId from the GCM Server and send it to our backend server. It is executed at the SDK initialization, and the regId is sent every time the app returns from background.

Notes

  • unregister() is not called, neither from server or client side
  • I am raising a toast with the registration id every once in a while, so I can verify it is the same between the client and the server:
Client side

Server side

2015-08-02 12:31:22,383 INFO - request_2145354041215926507 
                        update push token for user: XXXXXXXX,
                        push_token: ...me1GttmSRipnWsCGVUueK7e0nk

解决方案

Add Category with your package name to the intent-filter

  <receiver
        android:name=".xxxxx"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.xxxx" />
        </intent-filter>
    </receiver>

这篇关于Android SDK中被从GCM在几个小时后NotRegistered错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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