Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android GCM-Can';当应用程序被销毁时,无法接收消息_Android_Google Cloud Messaging - Fatal编程技术网

Android GCM-Can';当应用程序被销毁时,无法接收消息

Android GCM-Can';当应用程序被销毁时,无法接收消息,android,google-cloud-messaging,Android,Google Cloud Messaging,我正在研究GCM我在我的应用程序中部署了GCM,它工作正常,但那是以前的版本,现在我对GCM有了一些了解,我尝试在我的新版本中集成GCM。但我遇到了一个奇怪的问题,也许这是我明显缺少的东西。但现在,当应用程序被销毁时,我不会收到消息(当应用程序位于前台或后台时,我会收到消息)。另外,旧版本仍在接收消息 我在清单文件中添加了接收方和服务 <receiver android:name="com.google.android.gms.gcm.GcmReceiver"

我正在研究GCM我在我的应用程序中部署了GCM,它工作正常,但那是以前的版本,现在我对GCM有了一些了解,我尝试在我的新版本中集成GCM。但我遇到了一个奇怪的问题,也许这是我明显缺少的东西。但现在,当应用程序被销毁时,我不会收到消息(当应用程序位于前台或后台时,我会收到消息)。另外,旧版本仍在接收消息

我在清单文件中添加了接收方和服务

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.jadoo.jadooplus.gcm" />
        </intent-filter>
    </receiver>

    <service
        android:name="com.jadoo.jadooplus.gcm.PromotionalListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

    <service
        android:name="com.jadoo.jadooplus.gcm.services.MyInstanceIDListenerService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID"/>
        </intent-filter>
    </service>

    <service
        android:name="com.jadoo.jadooplus.gcm.services.RegistrationIntentService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

注意:请不要将此与强制停止应用程序混淆。

您可能还需要将注册权限添加到您的操作中。您的服务是粘性的吗?如果没有,请检查您的服务,可能您的应用程序正在销毁destroyed@MustanserIqbal我试试看。“但是我有足够的内存去运行。”Devsil我试过了,但是没有用。我很抱歉对你的评论投了赞成票,但这是一次意外的点击。“很显然,你不可能收回它。”阿巴斯。别担心。。。另一件需要检查的事情是,您也在清单中声明了所有适当的权限。
public class PromotionalListenerService extends GcmListenerService {

@Override
public void onMessageReceived(String from, Bundle data) {

    Log.d("Listener", "data=" + String.valueOf(data));

    if (from.startsWith("/topics/")) {

        //  topics messages
        if (Config.isActivityActive) {
            Intent messageReceived = new Intent(GcmConfig.MESSAGE_RECEIVED);
            messageReceived.putExtra(GcmConfig.MESSAGE_LABEL, data);
            LocalBroadcastManager.getInstance(this).sendBroadcast(messageReceived);
        }
        else {
            //  Show a notification
            sendNotification(data);
        }

    }
}