php - Notification generation issue in Android GCM -


i'm having following 2 problems:

first problem:

i have register 2 customers using same device, have same registration id.

when send offer server side both of these customers, notification being displayed should depend on logged in customer.

for example (see image):

enter image description here enter image description here in application have customer login form. in form, if user gnanavel logs in, app has receive offers alone, , not other's offers.

similarly, if user jeya logs in, app has receive offers alone, , not other's offers.

currently app receiving both offers.

edit:

i have created login status field in database.if customer logs in device means received notification offers alone.i didn't other's offers.its working well.

i have checked condition while click offer button:

 $getregid = mysqli_query($con,"select * pim_customers customer_id='$customer_id' , gcm_regid='$regid' , loginstatus='y'"); 

i wrote these condition means first problem solved.but raised problem.

the other problem is.,

when admin person enters offer, customer has receive notification on device when logged in customer. otherwise, notification shouldn't received. part working well.

the problem is, when customer logged out long time, , during time admin person entered more offers.

if customer logs in app after 2 days, should receive pending messages. how can pending messages?

admin side enters offers time customer logged out means loginstatus 'n' in database.so how can execute these condition , receive notification.

 $getregid = mysqli_query($con,"select * pim_customers customer_id='$customer_id' , gcm_regid='$regid' , loginstatus='y'"); 

this server side code executed when clicking offer button :

if (isset($_get["regid"]) && isset($_get["customer_id"]) && isset($_get["message"])) {   $regid = $_get["regid"];   $message = $_get["message"];   $customer_id = $_get["customer_id"];   include_once './gcm.php';   $getregid = mysqli_query($con,"select * pim_customers customer_id='$customer_id' , gcm_regid='$regid' , loginstatus='y'");   $count1=mysqli_num_rows($getregid);   while($row = mysqli_fetch_array($getregid))   {     $id=$row['customer_id'];   }   if (mysqli_num_rows($getregid) > 0) {     $query = mysqli_query($con,"select count(offer) count pim_productdeal customer_id='$id' , offer!=''");     $count = mysqli_fetch_array($query);     $msg = $count['count'];     $gcm = new gcm();     $registatoin_ids = array($regid);     $message = array("price" => $msg." "."the offers received");     $result = $gcm->send_notification($registatoin_ids, $customer_id, $message);     echo $result;   } } 

this android side code:

public class gcmintentservice extends gcmbaseintentservice {    private static final string tag = "gcmintentservice";   string regid;    public gcmintentservice() {     super(sender_id);   }    @override   protected void onregistered(context context, string registrationid) {     serverutilities.register(context, registeractivity.first_name, registeractivity.last_name, registeractivity.email, registeractivity.password, registrationid);   }    @override   protected void onunregistered(context context, string registrationid) {     log.i(tag, "device unregistered");     displaymessage(context, getstring(r.string.gcm_unregistered));     serverutilities.unregister(context, registrationid);   }    @override   protected void onmessage(context context, intent intent) {     log.i(tag, "received message");     gcmregistrar.checkdevice(this);     gcmregistrar.checkmanifest(this);     regid = gcmregistrar.getregistrationid(this);     string message = intent.getextras().getstring("price");     displaymessage(context, message);     if(constants.response != null) {       generatenotification(context,message);     }   }    @override   protected void ondeletedmessages(context context, int total) {     log.i(tag, "received deleted messages notification");     string message = getstring(r.string.gcm_deleted, total);     displaymessage(context, message);     // notifies user     generatenotification(context,message);   }    @override   public void onerror(context context, string errorid) {     log.i(tag, "received error: " + errorid);     displaymessage(context, getstring(r.string.gcm_error, errorid));   }    @override   protected boolean onrecoverableerror(context context, string errorid) {     // log message     log.i(tag, "received recoverable error: " + errorid);     displaymessage(context, getstring(r.string.gcm_recoverable_error,             errorid));     return super.onrecoverableerror(context, errorid);   }    private static void generatenotification(context context,string message) {     int icon = r.drawable.icon;     long when = system.currenttimemillis();     notificationmanager notificationmanager = (notificationmanager)             context.getsystemservice(context.notification_service);     notification notification = new notification(icon, message, when);      string title = context.getstring(r.string.app_name);      intent notificationintent = new intent(context, mydealproducts.class);     notificationintent.setflags(intent.flag_activity_clear_top |             intent.flag_activity_single_top);     pendingintent intent =             pendingintent.getactivity(context, 0, notificationintent, 0);     notification.setlatesteventinfo(context, title, message, intent);     notification.flags |= notification.flag_auto_cancel;     notification.defaults |= notification.default_sound;     notification.defaults |= notification.default_vibrate;     notificationmanager.notify(0, notification);         } } 

i edited question make easier understand. hope didn't change meaning. if did, apologize , ask correct me.

now answer:

  1. your server should aware user logged in device. should maintain in server table of logged in users, , each logged in user hold identifier of device in he/she logged in. in order have send request server each time user logs in or logs out. request should contain user id , device id. device id can either use registration id or use other id server generates (it might better generate id in server shorter registration id , therefore more efficient use. you'll have maintain table maps registration id device id).

  2. when admin creates new offer , assigns user, send gcm notification app if user logged in. therefore, in example of 2 users using same device, if 1 of them logged in, send single notification device logged in user. if none of them logged in, won't send notifications. store new offers in db , wait until 1 of them logs in.

  3. when gcm message arrives device, should make should addressed current logged in user, since it's possible 1 user logged out after message sent user logged in before arrived device. purpose, gcm message should include user identifier additional field. if message arrives device user id doesn't match current logged in user, discard message , don't display notification.

  4. when user logs in, server receive request (see #1). in response of request server should return device offers user has in server's db.

  5. as messages sent while device inactive long period of time - when device becomes active again, old messages might sent gcm (if haven't been discarded gcm yet). if these messages don't belong current logged in user, discard them (see #3). if belong current logged in user, should display them.

  6. i don't know php, limited understanding of server's code, seems send device gcm message contains number of offers user has. should use same collapse_key messages send. way, if multiple messages sent server while device offline, 1 of them sent device when becomes active again. don't need pending messages if contain number of available offers.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -