没有调用GCMBroadcastReceiver

时间:2015-02-23 13:16:45

标签: android broadcastreceiver google-cloud-messaging

我的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); } }

1 个答案:

答案 0 :(得分:1)

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