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

Not receiving push notifications from GCM (Android)

我正在使用这个 link 来测试我的推送通知。昨晚它工作正常,今天早上醒来,我不再收到推送通知。我在编写任何新代码之前对其进行了测试。用于测试的设备是Samsung Galaxy S5,OS是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>

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

看看这个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 的来源也将有助于提供帮助(您如何获取和处理令牌等)。

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