Android : Notification Manager only notify when the application is closed -


  1. i implemented broadcast receiver, @ onreceive() method notification manager code written.
  2. custom ringtone being played @ notification. on click of notification sound stops

issues failed do, if application open notification won't showed @ notification bar. expect of notification update ui of view[i.e. show stop button stop ringtone.]

notification code

public void sendnotification(context context, string title, string message, string filename)     {             final string ns = context.notification_service;             final notificationmanager notificationmanager = (notificationmanager)context.getsystemservice(ns);             final notification notification = new notification(r.drawable.ic_launcher, context.getstring(r.string.salahclock),  system.currenttimemillis());              intent intent = new intent( context, main.class);             intent.putextra("isalarmplaying", true);              //pending event open our application screen when notification clicked             final pendingintent contentintent = pendingintent.getactivity(context, 0, intent , 0);              notification.setlatesteventinfo(context, title, message, contentintent);             notification.sound = uri.parse("android.resource://path..");              notification.flags |= notification.flag_insistent;             notificationmanager.notify(1, notification);     } 

on recevie

public void onreceive(context context, intent intent) {  servicehandler = new handler(context);          powermanager pm = (powermanager) context.getsystemservice(context.power_service);          powermanager.wakelock wl = pm.newwakelock(powermanager.partial_wake_lock, "salah");          wl.acquire();           servicehandler.sendnotification(context, "", "", "");           wl.release();      } 

thanks,
salik

you can use static variable:

public static boolean sisactive = false; 

anywhere in project, , set true on activity onresume() , false on activity onpause().

than in receiver can check:

if (myclass.sisactive) { return; }  

and if not active, continue notification.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -