GCM 收不到消息

Posted

技术标签:

【中文标题】GCM 收不到消息【英文标题】:GCM cannot receive message 【发布时间】:2016-02-22 08:27:21 【问题描述】:

您好,我正在创建一个项目,而且我是谷歌云消息传递的新手,我正在使用 Eclipse 学习 androidhive 的 GCM 教程。 API Key 和 SENDER ID 已设置。我成功获得了 regId 并将其插入到我的服务器端。现在的问题是从我的服务器接收到我的应用程序的消息不会出现。

"multicast_id":6802394882982391839,"success":0,"failure":1,"canonical_ids":0,"results":["error":"MismatchSenderId"]

我像在tutorial中一样放置发件人ID

<!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<!-- GCM connects to Internet Services. -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
    android:name="com.jeffedward.pushnotifications.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

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

<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />

<!-- Main activity. -->
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <!-- Register Activity -->
    <activity
        android:name="com.jeffedward.pushnotifications.RegisterActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <!-- Main Activity -->
    <activity
        android:name="com.jeffedward.pushnotifications.MainActivity"
        android:configChanges="orientation|keyboardHidden"
        android:label="@string/app_name" >
    </activity>

    <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>

            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.jeffedward.pushnotifications" />
        </intent-filter>
    </receiver>

    <service android:name="com.jeffedward.pushnotifications.GCMIntentService" />
</application>

【问题讨论】:

【参考方案1】:

设置此权限

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

&lt;uses-permission android:name="android.permission.VIBRATE" /&gt;

并在您的代码中。 添加元数据

  <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <!-- Register Activity -->
         <meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
       </application>

【讨论】:

@integer/google_play_services_version 有点缺失

以上是关于GCM 收不到消息的主要内容,如果未能解决你的问题,请参考以下文章

企业微信号收不到消息

iOS 极光推送诶配置成功却收不到推送消息的处理

企业微信收不到消息是怎么回事

为啥我收到自己发来的消息,却收不到别人发来的消息。 XMPPFramework iOS

为啥我在 Swift5 中收不到推送消息?

为啥企业微信收不到消息通知