本文介绍了谷歌云消息(GCM)下行消息延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载并安装了Android GCM的客户端,并从的。我设法在我的Andr​​oid GCM的客户端应用程序来接收下行消息。我已经做了无数次的试验,具有以下特点:

I have downloaded and setup the Android gcm-client and gcm-demo-server (http server) from http://code.google.com/p/gcm/ . I have managed to receive downstream messages in my Android gcm-client app. I have done numerous tests with the following characteristics:


  1. 使用,也可以在浏览器API密钥或服务器API密钥服务器。

  2. 数据连接要么3G或WiFi

  3. 包括已发送的邮件/不包括额外的数据。

  4. 已发送的邮件有/没有崩溃的关键。

  5. 已发送的邮件必须delayWhileIdle设置为false。

  6. 已发送的邮件必须传输TimeToLive设置为0或5分钟。

  7. 服务器定位于两个不同的地点是在欧洲。

  8. 在两个设备的Andr​​oid应用程序运行分布在不同的地方是在欧洲。

在该应用从它们的发送时刻25-30秒后接收到发送的邮件的所有情况。使用GCM下行消息,在大多数情况下,邮件到达几乎立即但是,我已经测试过的其他Android应用(小于5秒)。

In all cases the app receives the sent messages after 25-30 sec from the moment they were sent. However, I have tested other Android applications that use GCM downstream messages and in most cases the messages arrive almost instantly (<5sec).

有什么我可以在客户端或服务器,以便在应用程序接收的消息改变越快?

Is there something I can change in the client or server in order to have the messages received in the app sooner?

我也尝试使用,但我没能发送的消息。我从GCM云连接服务器接收响应(CCS)说:项目XXXXXXXXXX未列入白名单。最可能的原因是我对CCM注册尚未在。正如我在各种网站已阅读,审批通常需要超过2-3个月,所以我最有可能不能够很快测试XMPP服务器。

I also tried to use the gcm XMPP server (Java application using Smack) given in http://developer.android.com/google/gcm/ccs.html but I didn't manage to sent any messages. The response I receive from GCM Cloud Connection Server (CCS) says "Project XXXXXXXXXX not whitelisted". The most possible reason is that my registration for CCM has not been approved yet as described in Google CCS (GCM) - project not whitelisted . As I have read in various websites, the approval usually takes more than 2-3 months, so I will most possibly not be able to test the XMPP server soon.

是否有可能,你只能通过使用XMPP服务器接收几乎即时消息?没有任何人有遇到的延迟任何经验,使用XMPP服务器?

Is it possible that you can only receive nearly instant messages by using an XMPP server? Does anybody have any experience of the delays encountered using an XMPP server?

在此先感谢

推荐答案

我认为这个问题是在被保留的消息,而不是在GCM服务器在Android GCM客户端的演示。
在GCM客户端演示GcmIntentService.java文件,可以看到该功能的保护无效onHandleIntent(意向意图)的有以下code:

I think that the problem is in the android gcm-client demo that are retaining the message, not in the gcm-server.In GcmIntentService.java file of gcm-client demo, it can be seen that the function protected void onHandleIntent(Intent intent) have the following code:

[...]
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// This loop represents the service doing some work.
    for (int i = 0; i < 5; i++) {
    Log.i(TAG, "Working... " + (i + 1)
            + "/5 @ " + SystemClock.elapsedRealtime());
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
    }
}
[...]

这code睡android应用5秒每次迭代(共25秒),之前传送通知消息。您可以删除这个code,由于是一个例子,你可以插入的否则,如果的声明显示通知之前的一些工作。

This code sleeps android application 5 seconds every iteration (total 25 seconds) before deliver a notification message. You can delete this code due to is an example and you can insert into else if statement some work before show notification.

我实现了一个XMPP服务器和我收到上述&lt通知; 5秒,没有这个工作code,当然

I have implemented a xmpp server and I receive the notification in <5 seconds, without this working code, of course.

希望这有助于和对不起我的英语不好。

Hope this help and sorry for my bad English.

这篇关于谷歌云消息(GCM)下行消息延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 02:56