Android 4.0.3上GcmBroadcastReceiver未被触发

4

我在应用程序中实现了GCM,遵循官方教程。 但是我的用户在Android 4.0.3以下版本报告通知无法正常工作。我发现GcmBroadcastReceiver extends BroadcastReceiveronReceive未被触发。 以下是我的清单文件。

    <!-- 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>

我做错了什么?
3个回答

5

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

在清单文件的权限部分中,你使用了com.myapp.gcm,在接收器的意图过滤器类别中使用了com.myapp。

在这两个地方,你应该使用相同的包名,即你的应用程序的主要包名。


哎呀,是的,你说得对,谢谢。应该是'com.myapp'。我会要求我的用户在更新后再试一次。我会告诉你结果的。 - Romain Pellerin

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>

您的清单文件权限缺失,请在清单文件中注册BroadcastReceiver


0

您的筛选器中缺少“com.google.android.c2dm.intent.REGISTRATION”操作,没有它,您的应用程序将无法接收到注册ID。请将以下内容添加到您的意图筛选器中:

action android:name="com.google.android.c2dm.intent.REGISTRATION"


官方文档没有提到这一点(请查看我提供的链接)。无论如何,在4.0.3以上,一切都正常工作,所以我不认为这可能是一个问题。 - Romain Pellerin

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