java - GCM is not sending the push notification to offline user upon login... dont know what I am missing? -


the phone trying receive push notification not receiving when user offline , comes online, regid , result returned not sure stopping it, not receiving error either...

edit: have user offline , come online, , message not pushed him, if user online @ time of push...

here code on server side:

// //below gcm function notifydetails(to, from, msg, itemid,  itemname, fromname, type) {  user.findone({_id: to}, function(err, results) {         if(err) {             throw err;          } else {                 callnotify();             function callnotify() {                 console.log("the " + results.reg_id);                 if(results != null) {                     request(                 { method: 'post',                 uri: 'https://android.googleapis.com/gcm/send',                 headers: {                     'content-type': 'application/json',                     'authorization': google api key                 },                      "registration_ids": [results.reg_id],                     "data": {                         "notifyfromuserid": from,                         "notifymsg": msg,                         "notifyitemid": itemid,                         "notifyitemname": itemname,                         "notifyfromname": fromname,                         "notifytype": type                       },                  //default 4 weeks (this in seconds)                     //"time_to_live": 20000                 })             }, function (error, response, body) {                 if(error) {                     throw error;                 } else {                      }                  });                 }          }             }       });    } 

on android manifest file:

<receiver             android:name=".modular.msgreceiver"             android:permission="com.google.android.c2dm.permission.send" >             <intent-filter>                 <action android:name="com.google.android.c2dm.intent.receive" />                 <category android:name="package.com" />             </intent-filter>         </receiver>          <service android:name=".modular.msgservice" /> 

the msgservice file:

public class msgservice extends intentservice {     sharedpreferences prefs;     notificationcompat.builder notification;     notificationmanager manager;      public msgservice() {         super("msgservice");     }      string tag = constants.debug;      @override     protected void onhandleintent(intent intent) {         bundle extras = intent.getextras();         googlecloudmessaging gcm = googlecloudmessaging.getinstance(this);         string messagetype = gcm.getmessagetype(intent);         prefs = getsharedpreferences("chat", 0);         if (!extras.isempty()) {             if (googlecloudmessaging.                     message_type_send_error.equals(messagetype)) {                 log.d(tag, "error");             } else if (googlecloudmessaging.                     message_type_deleted.equals(messagetype)) {                 log.d(tag, "error");             } else if (googlecloudmessaging.                     message_type_message.equals(messagetype)) {                  log.d(tag, "received: " + extras.getstring("notifymsg"));                 string notifyfromuserid, notifymsg, notifyitemid, notifyitemname, notifyfromname;                 int notifytype;                  notifyfromuserid = extras.getstring("notifyfromuserid");                 notifymsg = extras.getstring("notifymsg");                 notifyitemid = extras.getstring("notifyitemid");                 notifyitemname = extras.getstring("notifyitemname");                 notifyfromname = extras.getstring("notifyfromname");                 notifytype = extras.getint("notifytype");                 sendnotification(notifyfromuserid, notifymsg, notifyitemid, notifyitemname, notifyfromname, notifytype);                   }         }         msgreceiver.completewakefulintent(intent);     }      private void sendnotification(string notifyfromuserid, string notifymsg, string notifyitemid,                                   string notifyitemname, string notifyfromname, int notifytype) {          //the data want passed new class         bundle data = new bundle();         intent newintentmsg = new intent();               data.putstring("userid", notifyitemid);             intent profileintent = new intent(this, profileactivity.class);             profileintent.putextras(data);             newintentmsg = profileintent;            notification = new notificationcompat.builder(this);         notification.setcontenttitle(notifyitemname);         notification.setcontenttext(notifymsg);         notification.setticker("new message !");         notification.setsmallicon(r.drawable.ic_launcher);         pendingintent contentintent = pendingintent.getactivity(this, 1000,                 newintentmsg, pendingintent.flag_cancel_current);         notification.setcontentintent(contentintent);         notification.setautocancel(true);         manager =(notificationmanager) getsystemservice(context.notification_service);         manager.notify(0, notification.build());     } } 

the receiver file:

public class msgreceiver extends wakefulbroadcastreceiver {      //call new intent , grab data passed nodejs (extras)     @override     public void onreceive(context context, intent intent) {               bundle extras = intent.getextras();         intent msgrcv = new intent(context, msgservice.class);         msgrcv.putextra("notifyfromuserid", extras.getstring("notifyfromuserid"));         msgrcv.putextra("notifymsg", extras.getstring("notifymsg"));         msgrcv.putextra("notifyitemid", extras.getstring("notifyitemid"));             msgrcv.putextra("notifyitemname", extras.getstring("notifyitemname"));             msgrcv.putextra("notifyfromname", extras.getstring("notifyfromname"));             msgrcv.putextra("notifytype", extras.getint("notifytype"));             localbroadcastmanager.getinstance(context).sendbroadcast(msgrcv);         startwakefulservice(context,msgrcv);         setresultcode(activity.result_ok);     } } 

  1. what response receive gcm server when try send push message? please post response here. can diagnose problem my test push server help.
  2. in msgreceveier.onreceve unneceessary work when repack intent. set component existing intent , pass service:

    onreceive(context context, intent intent) {     intent.setcomponent(new componentname(context.getpackagename(),                                          msgservice.class.getname());     startwakefulservice(context,msgrcv);     setresultcode(activity.result_ok); } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -