I tried to use Google GCM, but when the application is closed (swipe or clear it from the task manager), it will not receive any push notifications. And when I open the application again, the notification has already disappeared and is lost.
GCM works for: - The application is open - The application is minimized.
Does not work: - The application is closed (swipe from the task manager) - The application is closed by clearing all open applications in the task manager
I want to receive push notifications, even if the application is closed just like Facebook or instagram. How can I achieve this? Is this possible in GCM? if so, how? if not, what is the other way to achieve this?
here is my code:
AndroidManifest.xml
<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.example.airwyntin.notificationtest" /> </intent-filter> </receiver> <service android:name=".MyGcmListenerService" android:exported="false" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service> <service android:name=".MyInstanceIDListenerService" android:exported="false"> <intent-filter> <action android:name="com.google.android.gms.iid.InstanceID"/> </intent-filter> </service> <service android:name=".RegistrationIntentService" android:exported="false"> </service>
MyGcmListenerService.java:
public class MyGcmListenerService extends GcmListenerService { private static int notifId = 0; private static final String TAG = "MyGcmListenerService";
MyInstanceIDListenerService.java:
public class MyInstanceIDListenerService extends InstanceIDListenerService { private static final String TAG = "MyInstanceIDLS";
RegistrationIntentService.java:
public class RegistrationIntentService extends IntentService { private static final String TAG = "RegIntentService"; private static final String[] TOPICS = {"global"}; public RegistrationIntentService() { super(TAG); } @Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {
heyou source share