2015-02-23 82 views
0

我的GCMBroadcastReceiver從不調用。我發了消息,從我的服務器通過PHP到GCM,我得到這個從GCM,所以我的服務器端應該工作:GCMBroadcastReceiver未調用

{"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

嘗試改變android:permission="com.google.android.cd2m.permission.SEND" 發給自:android:permission="com.google.android.c2dm.permission.SEND"

+0

謝謝你的工作 – Thomas 2015-02-23 13:38:33

+0

很高興幫助! – 2015-02-23 13:43:23

相關問題