I am implementing GCM for push notifications using GcmReceiver and GcmListenerService. When the application runs in the foreground or in the background, I get notifications just fine.
My problem is that I delete the application from the list of "recent tasks", I can no longer receive GCM messages (I am in Xiaomi Mi3). I understand that if you close the application, you will no longer receive push notifications. However, disconnecting from "recent tasks" should allow the application to receive push notifications.
I tested this with WeChat and Facebook Messenger, and I still get notifications when I uninstall the application (but not if I force it to close from the settings).
What am I doing wrong here?
manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.considerdigital.p1mobileapp" > <permission android:name="com.considerdigital.p1mobileapp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.considerdigital.p1mobileapp.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="com.google.android.c2dm.permission.SEND" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:name=".App" android:allowBackup="true" android:icon="@drawable/p1_app_icon" android:label="@string/app_name" android:theme="@style/Theme.P1mobileapp" > <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.considerdigital.p1mobileapp" /> </intent-filter> </receiver> <service android:name=".ListenerService" android:exported="false" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service>
GcmListenerService:
public class ListenerService extends GcmListenerService { private static final String TAG = "MyGcmListenerService"; public static final String FOREGROUND_NOTIFICATION = "FOREGROUND_NOTIFICATION"; private NotificationManager mNotificationManager; @Override public void onMessageReceived(String from, Bundle data) {
source share