未调用 GCMBroadcastReceiver

GCMBroadcastReceiver not called

我的 GCMBroadcastReceiver 从未被调用过。我通过 php 从我的服务器向 GCM 发送了一条消息,我从 GCM 收到了这条消息,所以我的服务器端应该可以正常工作:

{"multicast_id":XXX,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"XXXX"}]}

所以问题必须在我的AndroidManifest中,但我找不到解决方案,你们能帮帮我吗?

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<permission
    android:name="com.example.administrator.test.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".RealMainActivity"
        android:label="@string/title_activity_real_main"
        android:noHistory="true" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <receiver
        android:name="com.example.administrator.test.GcmBroadcastReceiver"
        android:permission="com.google.android.cd2m.permission.SEND" >
        <intent-filter>
            <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.example.administrator.test" />
        </intent-filter>
    </receiver>

    <service
        android:name="com.example.administrator.test.GcmIntentService">
    </service>
</application>

GCMBroadCastReceiver.java

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); Log.i("GCMBroadcastreceiver", "werkt"); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); } }

尝试更改 android:permission="com.google.android.cd2m.permission.SEND" 至:android:permission="com.google.android.c2dm.permission.SEND"