java - notification for low battery -


i trying pop notification when device have under 15% battery left. shows notification every time, when have on 15%.

this code:

public class mainactivity extends activity {  public int battery, level; private static final int dialog_exit=1; button hscore,toinfo,toproj; imageview easter,exit,help,info;  private textview contenttxt;     public broadcastreceiver mbatinforeceiver = new broadcastreceiver(){         @override         public void onreceive(context arg0, intent intent) {           // todo auto-generated method stub           level = intent.getintextra("level", 0);               contenttxt.settext(string.valueof(level) + "%  battery");                }       };    @override protected void oncreate(bundle savedinstancestate)  {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      this.registerreceiver(this.mbatinforeceiver, new intentfilter(intent.action_battery_changed));      contenttxt = (textview) this.findviewbyid(r.id.txtbattery);      if(level <= 15)     {         intent charge = new intent(mainactivity.this,chargeactivity.class);         //  intent st =new intent(android.provider.settings.action_settings);                    string title="you have low battery", message="charge phone";             int icon = r.raw.duck_yellow;                 int mnotificationid = 001;              pendingintent resultpendingintent =                     pendingintent.getactivity(                             getbasecontext(),                             0,                             charge,                             pendingintent.flag_cancel_current                     );                notificationcompat.builder mbuilder = new notificationcompat.builder(                     getbasecontext());             notification notification = mbuilder.setsmallicon(icon).setticker(title).setwhen(0)                     .setautocancel(true)                     .setcontenttitle(title)                     .setstyle(new notificationcompat.bigtextstyle().bigtext(message))                     .setcontentintent(resultpendingintent)                     .setsound(ringtonemanager.getdefaulturi(ringtonemanager.type_notification))                     .setlargeicon(bitmapfactory.decoderesource(getbasecontext().getresources(), r.raw.duck_yellow))                     .setcontenttext(message).build();              notificationmanager notificationmanager = (notificationmanager) getbasecontext().getsystemservice(context.notification_service);             notificationmanager.notify(mnotificationid, notification);     } 

what should fix this? think private/public variables


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -