没有收到来自GCM(Android)的推送通知

时间:2015-10-14 18:48:06

标签: android push-notification google-cloud-messaging

我正在使用此link来测试我的推送通知。昨晚它工作正常,今天早上醒来,我不再收到推送通知。我在编写任何新代码之前测试过它。用于测试的设备是三星Galaxy S5,操作系统是Lollipop。

这是我的清单,如果您需要查看我的任何服务,请告诉我。

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

    <uses-permission android:name=".permission.C2D_MESSAGE" />

    <application
        ....
        ....

        <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.fullpackage.name.gcm" />
            </intent-filter>
        </receiver>

        <service
            android:name=".services.MyGcmListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <service
            android:name=".services.MyInstanceIDListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID" />
            </intent-filter>
        </service>

我没有收到错误,它说我的服务器和上面的测试链接都成功发送了消息。我已经尝试卸载应用程序并生成新令牌,但它仍无法正常工作。每次加载应用程序时,我也能成功检索我的令牌。

1 个答案:

答案 0 :(得分:3)

看看这个official tutorial。好像你错过了将包名添加到权限。

<permission
    android:name="your.package.name.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="your.package.name.permission.C2D_MESSAGE" />

您的MyGcmListenerService和MyInstanceIDListenerService的来源也可以提供帮助(如何获取和处理令牌等)。

或者,如果你说它昨天工作正常,请尝试启用然后禁用飞行模式,或重新启动手机。