0

我制作了一个正在从我的服务器接收GCM消息的应用程序。我试图实现谷歌样本(http://developer.android.com/google/gcm/client.html#sample-receive)。除非是问题,否则它正常工作。这就是说,如果我在内存中杀了我的应用程序,我的广播接收器将永远不会收到GCM消息。
我试图让设备的日志,看看这个问题是关于GTalkService:
关闭应用程序时无法接收GCM

01-15 14:19:40.509: W/GTalkService(1300): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.paktor (has extras) } 
01-15 14:19:40.750: W/GTalkService(1300): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.paktor (has extras) } 
01-15 14:19:41.090: W/GTalkService(1300): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.paktor (has extras) } 

我的接收机是的manifest.xml:

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

更新时间: 我的广播:

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { 

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

并且权限:

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

我不知道为什么。每件事看起来都像正常。请帮我知道如何在我的应用程序被杀时捕获GCM消息。

+0

我想你需要看WakeLocker在Android的设置delay_while_idle=0。 http://developer.android.com/reference/android/os/PowerManager.WakeLock.html – alicanbatur

+0

我添加了android.permission.WAKE_LOCK这不是问题 –

回答

0

WakefulBroadcastReceiver这样

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()); 
     // Start the service, keeping the device awake while it is launching. 
     startWakefulService(context, (intent.setComponent(comp))); 
     setResultCode(Activity.RESULT_OK); 
    } 
} 

许可

+0

我以前这样实现。我想这不是问题 –

相关问题