android - addProximityAlert is not working if Location service is disabled -


i'm using locationmanager#addproximityalert function alert user when enter range of places, if location service enabled works fine , notifications, when location disabled nothing. need receive alerts if location not enabled, here code:

locationmanager = (locationmanager) getsystemservice(context.location_service);     locationmanager.requestlocationupdates(locationmanager.network_provider,             minimum_time_between_update, minimum_distancechange_for_update,             new locationlistener()); public void preparenotifications() { // nearproductslocs array of locations  (int = 0; < nearproductslocs.length; i++) {     log.d(tag, "order" + + " " nearproductslocs[i]);     // +++++++++++++++++++++++++++++++++++++++++++++++++     // add addproximityalerts     location loc = nearproducts[i];     addproximityalert(loc.getlatitude(), loc.getlongitude()); } } private void addproximityalert(double latitude, double longtitude, int productid) { intent intent = new intent(prox_alert_intent); intent.putextra("productid", productid); pendingintent proximityintent = pendingintent.getbroadcast( scontext.getapplicationcontext(), 0, intent, pendingintent.flag_cancel_current); locationmanager.addproximityalert(latitude, longtitude, point_radius, prox_alert_expiration,proximityintent); intentfilter filter = new intentfilter(prox_alert_intent); scontext.registerreceiver(new proximityintentreceiver(), filter); } 

and proximityintentreceiver here:

public class proximityintentreceiver extends broadcastreceiver {  @override public void onreceive(context context, intent xintent) {      string key = locationmanager.key_proximity_entering;     boolean entering = xintent.getbooleanextra(key, false);     int productid = xintent.getintextra("productid", 0);     log.d("productid", "" + productid);      if (entering) {          intent offerintent = new intent(context, item.class);         offerintent.putextra("productid", productid);          pendingintent pintent = pendingintent.getactivity(context, productid, offerintent, pendingintent.flag_update_current);         notificationmanager notificationmanager = (notificationmanager) context.getsystemservice(context.notification_service);         notification mynotification = new notification(r.drawable.logo, "nearby product!",system.currenttimemillis());         createnotification(mynotification);         mynotification.setlatesteventinfo(context, "monim", "check amazing product!", pintent);         notificationmanager.notify(productid, mynotification);     }  } 


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -