Android GCM接收器在应用程序空闲一段时间时不工作,但在应用程序打开时工作正常

Android GCM接收器在应用程序空闲一段时间时不工作,但在应用程序打开时工作正常,android,google-cloud-messaging,Android,Google Cloud Messaging,我已经在我的应用程序中实现了GCM推送通知,它运行良好。接收器在应用程序处于前台或后台时接收。但当应用程序处于后台时,某些特定手机上的接收器无法接收。我做错了什么 AndroidManifest.xml <uses-sdk android:minSdkVersion="12" android:targetSdkVersion="22" /> <uses-permission android:name="android.permission.WAKE_L

我已经在我的应用程序中实现了GCM推送通知,它运行良好。接收器在应用程序处于前台或后台时接收。但当应用程序处于后台时,某些特定手机上的接收器无法接收。我做错了什么

AndroidManifest.xml

    <uses-sdk
    android:minSdkVersion="12"
    android:targetSdkVersion="22" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"    />
<uses-permission android:name="com.google.android.c2dm.permission.REGISTER" />
<permission
    android:name="com.testapp.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.testapp.permission.C2D_MESSAGE" />

 <application
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:hardwareAccelerated="true"
    android:theme="@style/AppTheme" 
    android:killAfterRestore="false"        
    android:allowClearUserData="false">

 <receiver
        android:name="com.testapp.ExternalReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.google.android.c2dm.intent.REGISTER" />
            <action android:name="com.testapp" />

            <category android:name="com.testapp" />
        </intent-filter>
    </receiver>

    <service android:name="com.testapp.GCMService" />

 </application>
你必须改变:

<receiver
        android:name="com.testapp.ExternalReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.google.android.c2dm.intent.REGISTER" />
            <action android:name="com.testapp" />

            <category android:name="com.testapp" />
        </intent-filter>
    </receiver>

为此:

<receiver
        android:name=".GcmBroadcastReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.google.android.c2dm.intent.REGISTER" />
            <action android:name="com.testapp" />

            <category android:name="com.testapp" />
        </intent-filter>
    </receiver>


就一行

这些设备是否能够在GCM上注册??你能得到他们的注册码吗?是的,我可以在应用程序运行时注册并发送和接收消息。只有在应用程序处于后台时,我才能接收消息。这发生在华为荣誉手机上,我已经尝试了多台设备。那么在这种情况下,我猜这些设备正在阻止后台数据,您应该从设备设置启用它,以便其他应用程序即使在后台也能正常运行。我们是否可以在清单中定义任何设置以阻止它?
<receiver
        android:name=".GcmBroadcastReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.google.android.c2dm.intent.REGISTER" />
            <action android:name="com.testapp" />

            <category android:name="com.testapp" />
        </intent-filter>
    </receiver>