android - Not receiving GCM notifications with app in background and content-available=1 -


i developing ionic 2 app , testing on android emulator.

when app in background , notification has no title, no message , content-available=1 notification should sent directly app notification handler. not happening.

i can receive notifications app in foreground.

if have title , message receive notification in notification area. need send notification directly app in silent mode, without pass notification area.

here code send push notifications:

{    "delay_while_idle": true,    "priority": "high",    "sound": "default",    "color": "ffff00",    //payload       "data": {        "content-available": "1",        "some_var": "some_value",        "ohter_var": "other_value",           } } 

how sent silent notifications android app?

android gcm , fcm both work when app background.

for need add below service classes @ manifest intent filter.

<!-- [start gcm_listener] -->         <service             android:name=".gcm.gcmlistener"             android:exported="false">             <intent-filter>                 <action android:name="com.google.android.c2dm.intent.receive" />             </intent-filter>         </service>         <service             android:name=".gcm.tokenrefreshservice"             android:exported="false">             <intent-filter>                 <action android:name="com.google.android.gms.iid.instanceid" />             </intent-filter>         </service>         <service             android:name=".gcm.registrationintentservice"             android:exported="false" />         <!-- [end gcm_listener] -->   public class gcmlistener extends gcmlistenerservice { }   public class tokenrefreshservice extends instanceidlistenerservice {     @override     public void ontokenrefresh() {         super.ontokenrefresh();         intent intent = new intent(this, registrationintentservice.class);         startservice(intent);     } } 

to token:

public class registrationintentservice extends intentservice {     // todo: rename actions, choose action names describe tasks     private string tag = "registrationintentservice";      public registrationintentservice() {         super("registrationintentservice");     }       @override     protected void onhandleintent(intent intent) {      instanceid instanceid = instanceid.getinstance(this);         string token = instanceid.gettoken("product_id",                 googlecloudmessaging.instance_id_scope, null); } } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -