Android:无法接收未被调用的GCM消息/侦听器 [英] Android: Unable to receive GCM Messages/ Listener not being called

查看:116
本文介绍了Android:无法接收未被调用的GCM消息/侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我错过了一些内容,但我不确定考虑遵循指南的内容,例如: https ://developers.google.com/cloud-messaging/android/client



以及检查我的代码: https:// github.com/googlesamples/google-services/tree/master/android/gcm/app/src/main/java/gcm/play/android/samples/com/gcmquickstart



我的服务器端代码是正确的,它会成功发送一个 GCM 消息,但我的Android客户端不会收到任何东西。



我认为问题出现在清单中的某处:
$ b Manifest.xml

 <?xml version =1.0encoding =utf-8?> 
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =com.mypackage.here
android:versionCode = 1
android:versionName =1.0>

< uses-sdk
android:minSdkVersion =16
android:targetSdkVersion =21/>

< permission
android:name =com.mypackage.here.permission.C2D_MESSAGE
android:protectionLevel =signature/>

<使用权限android:name =android.permission.INTERNET/>
<使用权限android:name =android.permission.WAKE_LOCK/>
< uses-permission android:name =com.mypackage.here.permission.C2D_MESSAGE/>

< application
android:allowBackup =true
android:icon =@ drawable / ic_launcher
android:label =@ string / app_name
android:theme =@ style / AppTheme>
< meta-data
android:name =com.google.android.gms.version
android:value =@ integer / google_play_services_version/>

< activity
android:name =。MainActivity
android:label =@ string / app_name>
< intent-filter>

< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>

<! - C2DM服务接收 - >
<! - [START gcm_receiver] - >
< receiver
android:name =com.google.android.gms.gcm.GcmReceiver
android:exported =true
android:permission =com。 google.android.c2dm.permission.SEND>
< intent-filter>

< category android:name =com.mypackage.here/>
< / intent-filter>
< / receiver>
<! - [END gcm_receiver] - >


<! - [START gcm_listener] - >
< service
android:name =。EPAOAGcmListenerService
android:exported =false>
< intent-filter>
< / intent-filter>
< / service>
<! - [END gcm_listener] - >
<! - - [START instanceId_listener] - >
< service
android:name =。EPAOAInstanceIDListenerService
android:exported =false>
< intent-filter>
< / intent-filter>
< / service>
<! - [END instanceId_listener] - >
< service
android:name =。EPAOAGcmRegisterIntentService
android:exported =false>
< / service>
<! - C2DM服务接收结束 - >

< / application>

< / manifest>

我会注意到我正在注册并接收设备令牌。我只是无法收到消息(通知)。如果在通过清单查看时没有立即想到,请注意是否应该提出有关下一个应该看的地方的建议。 解决方案

简单的答案是:不用担心!第一次明显需要一些时间!这是因为Google服务器发生了同步。



此外,如果它的通知延迟时间可能需要15-28分钟,因为:
客户端电话上的GCM框架部分在端口5228上使用TCP连接。该连接用于推送通知,但作为每个tcp连接,它可以与一些应用严格策略来终止非活动tcp连接的路由器/运营商超时tcp idle timeout)。



大多数wifi路由器在5分钟后杀死不活动的连接,例如,像我的一样。



GCM框架使用保活机制在wifi上每15分钟发送一次心跳网络数据包,在3G上每28分钟发送一次心跳网络数据包。

I am missing something and I am not sure what considering I followed the guide ie: https://developers.google.com/cloud-messaging/android/client

as well as checked my code against: https://github.com/googlesamples/google-services/tree/master/android/gcm/app/src/main/java/gcm/play/android/samples/com/gcmquickstart

My server side code is correct will successfully send out a GCM message but my android client does not receive anything.

I am thinking the issue lies somewhere in the manifest:

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mypackage.here"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="21" />

    <permission
        android:name="com.mypackage.here.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.mypackage.here.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- C2DM service Receive -->
        <!-- [START gcm_receiver] -->
        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />

                <category android:name="com.mypackage.here" />
            </intent-filter>
        </receiver>
        <!-- [END gcm_receiver] -->


        <!-- [START gcm_listener] -->
        <service
            android:name=".EPAOAGcmListenerService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <!-- [END gcm_listener] -->
        <!-- [START instanceId_listener] -->
        <service
            android:name=".EPAOAInstanceIDListenerService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID" />
            </intent-filter>
        </service>
        <!-- [END instanceId_listener] -->
        <service
            android:name=".EPAOAGcmRegisterIntentService"
            android:exported="false" >
        </service>
        <!-- C2DM service Receive End -->

    </application>

</manifest>

I will note that I am registering and receiving the device token perfectly fine. I just cannot receive messages (notifications). If no immediate thoughts come to mind while looking through the manifest, it would be appreciated if a suggestion were to be made about the next place I should look.

解决方案

Simple answer is: not to worry! For the first time it is obvious to take some time! It is attributed to the synchronization that happens in the Google Servers.

Furthermore, if its Notifications it can take up to 15-28 min delay, because: The GCM framework part on the client phone use a TCP connection on the port 5228. This connection its used for push notifications, but as every tcp connection it can go on timeout with some routers/carriers that apply strict policies to kill inactive tcp connections (tcp idle timeout).

Most wifi routers kills inactive connections after 5 minutes for example, like mine.

The GCM framework use a keep-alive mechanism to send an heartbeat network packet every 15 minutes on wifi and every 28 minutes on 3G.

这篇关于Android:无法接收未被调用的GCM消息/侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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