无法从GCM(Android)接收推送通知

3
我正在使用此链接测试我的推送通知。昨晚它工作得很好,但早上醒来后,我不再收到推送通知。在编写任何新代码之前,我进行了测试。用于测试的设备是三星Galaxy S5,操作系统为棒棒糖。

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

<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个回答

3
看看这个官方教程。似乎你忘了将你的包名添加到权限中。
<permission
    android:name="your.package.name.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

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

您的MyGcmListenerService和MyInstanceIDListenerService源代码是有用的,它们可以帮助您获取并处理令牌等信息。

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


我已经尝试了两种方式。快速的.permission.C2D_MESSAGE和完整描述的my.package.name.permission.C2D_MESSAGE。教程已经仔细阅读。 - i_me_mine
重启设备就是我需要的一切。谢谢! - i_me_mine
那么以“.”开头是可以的,对吗?如果是这样,为什么在检查权限是否已授予时会显示未授予呢?我在这里询问过:https://dev59.com/E5Dea4cB1Zd3GeqPeqqw - android developer
这里不允许使用“.”作为开头。 - keybee

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接