4

按照这个官方教程,我已经在我的应用程序中实现了GCM。但是我在Android 4.0.3下的用户报告我的通知不起作用。我发现我没有被解雇。这是我的清单。onReceiveGcmBroadcastReceiver extends BroadcastReceiver

    <!-- GCM -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.VIBRATE" />

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

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

    <application
        ... >

        <!-- GCM -->
        <receiver
            android:name="com.myapp.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />

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

我究竟做错了什么?

4

3 回答 3

5

您的应用程序的主包名称是 com.nyapp.gcm 还是 com.myapp?

在清单的权限部分中,您使用 com.myapp.gcm,而在接收者的意图过滤器类别中,您使用 com.myapp。

在这两个地方,您应该使用相同的包,这是您的应用程序的主包。

于 2013-07-24T04:39:12.810 回答
0

您在过滤器中缺少操作“com.google.android.c2dm.intent.REGISTRATION”,否则您的应用将无法接收注册 ID。将以下内容添加到您的意图过滤器:

动作 android:name="com.google.android.c2dm.intent.REGISTRATION"

于 2013-07-24T03:07:52.337 回答
0
<!-- GCM -->
    <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="YOUR_APP_PACKAGE_NAME" />
        </intent-filter>
    </receiver>

您的清单文件权限缺失检查清单文件中的广播接收器注册

于 2013-10-09T04:32:31.743 回答