GCM谷歌服务器空消息响应 [英] GCM Google server responding with null message

查看:207
本文介绍了GCM谷歌服务器空消息响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面<一href="http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/"相对=nofollow>这个链接,但发送消息到GCM API后,我的Andr​​oid收到一个空消息(值设置为)。

I am following this link, but after sending a message to the GCM API my Android receives an empty message (value set to null).

这是我的Django的查看,发送消息到GCM API:

This is my Django View, sending the message to the GCM API:

@csrf_exempt
def send_notification(request):
    message = {"name": "Kousik","email": "kousik.tict@gmail.com"}
    registration_ids = ['xxxxxxxxxxxxxxx','xxxxxxxxxxxxxxxxxx']
    post_data = {"data":message,"registration_ids":registration_ids}
    headers = {'Content-Type': 'application/json', 'Authorization':'key=xxxxxxxxx'}
    import requests    
    post_response = requests.post(url='https://android.googleapis.com/gcm/send', data=simplejson.dumps(post_data), headers=headers)
    to_json = {'status':str(post_response)}
    return HttpResponse(simplejson.dumps(to_json), mimetype='application/json')

不过,流量报告显示正在发送的任何消息都:

However, the traffic report shows no messages being sent at all:

Android的code接收GCM消息:

Android Code receiving the GCM message:

static final String EXTRA_MESSAGE = "message";
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        for(String key: bundle.keySet()){
            Log.d("gen", key+" - "+bundle.get(key));
        }


        String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
        //newMessage comming NULL
        // Waking up mobile if it is sleeping
        WakeLocker.acquire(getApplicationContext());


        // Showing received message
        lblMessage.append(newMessage + "\n");           
        Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG).show();

        // Releasing wake lock
        WakeLocker.release();
    }
};

我把一个破发点,并在这里我得到了以下内容:

I put a break point here and I got the following:

注意的消息 HashMap中的值,它是

Note the message value in the hashmap, it is null.

推荐答案

这里有一些事情我可以说:

Here are some things I can say :

  1. 谷歌API控制台不显示GCM统计数据,告诉你应该不希望看到任何东西在那里。

  1. Google APIs console doesn't show GCM statistics, show you shouldn't expect to see anything there.

您的服务器不发送的消息键(也只发送名称电子邮件,所以我不知道有什么的消息键是在调试器的截图空。

Your server doesn't send a message key (it sends only name and email, so I don't know what's the message key that is null in the debugger screenshot.

我不明白这行:

私人最终的BroadcastReceiver mHandleMessageReceiver =新的BroadcastReceiver()

您不必实例化从GCM接收消息的BroadcastReceiver。你应该在你的清单中声明它,如图很多教程(包括官方GCM编程指南)。

You don't have to instantiate the BroadcastReceiver that receives the messages from GCM. You should declare it in your manifest as shown on many tutorials (including the official GCM programming guide).

我的猜测是,你在本地调用的BroadcastReceiver在你的应用程序,你是从你的服务器发送邮件没有达到应用程序。

My guess is that you are invoking the BroadcastReceiver locally in your app, and the message you are sending from your server is not reaching the app.

您应该包括从谷歌服务器获得响应你的问题,让我们可以肯定这个问题是不是在你的服务器端。你还应该包括你的清单。

You should include the response your server gets from Google in your question, so that we can be sure the problem is not on your server side. You should also include your manifest.

这是不完全的答案,但它太长了评论,我认为它可以解决你的问题的方向指向你。

This is not exactly an answer, but it's too long for a comment, and I think it can point you in the direction of solving your problem.

这篇关于GCM谷歌服务器空消息响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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