为什么我无法在Android设备上接收来自GCM的消息 [英] Why I can't receive messages from GCM on android device

查看:111
本文介绍了为什么我无法在Android设备上接收来自GCM的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个需要发送gcm消息的android应用程序。

到目前为止,我设法获取设备ID 并将其发送到我的服务器。
现在,当我尝试将消息从我的服务器推送到我的应用时,我收到以下消息: {multicast_id:4987023356709284342,success:1,failure:0,canonical_ids :0,results:[{message_id:0:1430085972465424%73c650e3f9fd7ecd}]} ,但设备上没有任何事情发生(应用程序是否正在运行并不重要)。



以下是我的相关代码:



Manifest.xml ---------- ------- AndroidManifest.xml

BroadcastReceiver -------- GcmBroadcastReceiver

IntentService ---------------- GcmIntentService

注册---------------------- GcmRegister


这里我使用注册类(查找' GCM HERE '标签)

LoginActivity ---------------- LoginActivity


这里是我的android项目结构

结构--- ------------------ 结构


服务器端[PHP]

GcmPush ------------- ------ GcmPush.php

,这就是我如何使用GcmPush.php

SendMessage -------------- 发送功能



<希望有人能帮助我。

指出我做错了什么....
谢谢!

解决方案

最后我发现...

我将日志放在 GcmReceive 中,并打印日志:),然后我去了 IntentServices ,并且在那里我发现该消息已得到提示,但通知并未实际通知该消息。

到目前为止,我还没有发现什么问题是我的通知,但我认为是s这条线错了:

  PendingIntent contentIntent = PendingIntent.getActivity(this,0,new Intent(this,MainActivity.class) ,0); 

我很高兴最大的问题解决了。现在我正在搜索我在通知中做了什么错误。



非常感谢所有试图帮助您的人......


I am creating an android application where I need to send gcm messages.
So far I managed to get device id and to sent it to my server. Now when I'm trying to push a message from my server to my app, I receive this message : {"multicast_id":4987023356709284342,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1430085972465424%73c650e3f9fd7ecd"}]}, but nothing happens on the device (doesn't matter if the app is running or not).

Here is my relevant code:


Manifest.xml----------------- AndroidManifest.xml
BroadcastReceiver-------- GcmBroadcastReceiver
IntentService---------------- GcmIntentService
Register---------------------- GcmRegister

here I am using the register class (look for 'GCM HERE' tag)
LoginActivity---------------- LoginActivity

here is my android project structure
Structure--------------------- structure

Server side [PHP]
GcmPush ------------------- GcmPush.php
and this is how I'm using GcmPush.php
SendMessage-------------- send function

Hope someone can help me.
To point what I'm doing wrong.... Thank you!

解决方案

Finally I found...
I put logs in GcmReceive, and it prints the log :), then I went to IntentServices, and there I found that the message has arived but notification didn't actually notify the message.
So far I didn't found yet what the problem is with my notification but, I think is something wrong with this line :

 PendingIntent contentIntent = PendingIntent.getActivity(this, 0,  new Intent(this, MainActivity.class), 0);

I am glad that the biggest problem is solved. Now I am searching arround what I'm doing wrong with Notification.

Thanks very much to everyone who tried to help...

这篇关于为什么我无法在Android设备上接收来自GCM的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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