java - Android Proximity alert with multiple POI -


i have database of lat , long id's , have retrieved using json , want apply proximity alert geo locations in array. unsure if array being passed or if proximity alert.java being invoked properly

this db retrieval

public class retrievedb extends asynctask<void, integer, void> {  @override protected void doinbackground(void... params) {      string result = "";     inputstream = null;      //http post     try{             httpclient httpclient = new defaulthttpclient();             httppost httppost = new httppost("http://cs1.ucc.ie/~am32/getdb.php");             httpresponse response = httpclient.execute(httppost);             httpentity entity = response.getentity();             = entity.getcontent();     }     catch(exception e){             log.e("log_tag", "error in http connection "+e.tostring());      }     //convert response string     try{             bufferedreader reader = new bufferedreader(new inputstreamreader(is, "iso-8859-1"),8);             stringbuilder sb = new stringbuilder();             sb.append(reader.readline() + "\n");              string line = null;             while ((line = reader.readline()) != null) {                     sb.append(line);             }             is.close();             result=sb.tostring();              log.i("json string", result);     }     catch(exception e){             log.e("log_tag", "error converting result "+e.tostring());     }      //parse json data     try{             jsonarray jarray = new jsonarray(result);             jsonobject json_data = null;              system.out.println("length"+ jarray.length());             log.d("db","length"+jarray.length());              for(int i=0; i<jarray.length(); i++){                      json_data = jarray.getjsonobject(i);                     int id = json_data.getint("id") ;                     //string title = json_data.getstring("title");                      double latitude = json_data.getdouble("lat");                      double longitude = json_data.getdouble("lon");                       //adds proximity poi's                     proxalert inst = new proxalert();                     inst.addproximityalert(latitude,longitude, id);                     //                     inst.savecoordinatesinpreferences((float)latitude, (float)longitude);                      //prints logcat                     system.out.println(id+"&"+latitude+"&"+longitude);               }     }     catch(jsonexception e){             log.e("log_tag", "error parsing data "+e.tostring());             log.e("log_tag","failed data as:\n"+result);     }         return null; }  @override protected void onprogressupdate(integer... values) {     // invoked on ui thread publishprogress(progress...).     super.onprogressupdate(values); }  @override protected void onpostexecute(void result) {     // result of background comp passed step invoked on ui thread     super.onpostexecute(result);  } 

}

and proximity alert class

public class proxalert extends activity {  private static final long point_radius = 10; private static final long prox_alert_expiration = -1;  private static final string point_latitude_key = "point_latitude_key"; private static final string point_longitude_key = "point_longitude_key";  private locationmanager locationmanager; private static final string prox_alert_intent= "com.example.try0.proximityintentreceiver";  void addproximityalert (double latitude, double longitude, int id){      bundle extras = new bundle();     extras.putint("title", id);     extras.putdouble("lat", latitude);     extras.putdouble("lon", longitude);      intent intent = new intent(prox_alert_intent + id);     //intent.putextra("alert", "it works");     intent.putextra(prox_alert_intent, extras);     pendingintent proximityintent = pendingintent.getbroadcast(this, id, intent, pendingintent.flag_cancel_current);      //proximityintent used generate intent fire when entry or exit alert region detected     locationmanager.addproximityalert(latitude,longitude,point_radius,prox_alert_expiration,proximityintent);      intentfilter filter = new intentfilter(prox_alert_intent + id);     registerreceiver(new proximityintentreciever(), filter);  }  void savecoordinatesinpreferences(float currentlatitude, float currentlongitude){     sharedpreferences prefs = this.getsharedpreferences(getclass().getsimplename(), context.mode_private);     sharedpreferences.editor prefseditor = prefs.edit();     prefseditor.putfloat(point_latitude_key, currentlatitude);     prefseditor.putfloat(point_longitude_key, currentlongitude);     prefseditor.commit(); }  location retrievelocationfrompreferences(){     sharedpreferences prefs = this.getsharedpreferences(getclass().getsimplename(), context.mode_private);     location location = new location("point_location");     location.setlatitude(prefs.getfloat(point_latitude_key, 0));     location.setlongitude(prefs.getfloat(point_longitude_key, 0));     return location; } 

}

i'd appreciate been lot of staring , confusing

here service, works perfectly, know on market, database if plug in json maybe can alter needs

import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.app.service; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.content.intentfilter; import android.database.cursor; import android.graphics.color; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.os.bundle; import android.os.ibinder; import android.util.log; import android.widget.toast;   public class proximityservice extends service{     string proximitysd = "com.apps.proximityservice";     int n = 0;     private broadcastreceiver mybroadcast;     private locationmanager locationmanager;     mylocationlistener locationlistenerp;     public proximityservice() {       }      @override     public ibinder onbind(intent intent) {         // todo auto-generated method stub         return null;     }     @override     public void oncreate() {         mybroadcast = new proximityintentreceiver();         locationmanager = (locationmanager)                  getsystemservice(context.location_service);              double lat;         double lng;         float radius = 50f;         long expiration = -1;          mydbadapter db = new mydbadapter(this);             cursor cursor;             db.read();             cursor = db.getallentries();             boolean go = cursor.movetofirst();             while(cursor.isafterlast() != true){                 lat = cursor.getint(mydbadapter.latitude_column)/1e6;                 lng = cursor.getint(mydbadapter.longitude_column)/1e6;                 string = cursor.getstring(mydbadapter.icon_column);                 string how = cursor.getstring(mydbadapter.fish_column);                 string proximitys = "com.apps.proximityservice" + n;                 intentfilter filter = new intentfilter(proximitys);                 registerreceiver(mybroadcast, filter );                  intent intent = new intent(proximitys);                  intent.putextra("alert", what);                 intent.putextra("type", how);                 pendingintent proximityintent = pendingintent.getbroadcast(this, n, intent, pendingintent.flag_cancel_current);                 locationmanager.addproximityalert(lat, lng, radius, expiration, proximityintent);                 //sendbroadcast(new intent(intent));                  n++;                 cursor.movetonext();             }             db.close();             cursor.close();     }      @override     public void ondestroy() {         toast.maketext(this, "proximity service stopped", toast.length_long).show();         try{             unregisterreceiver(mybroadcast);         }catch(illegalargumentexception e){             log.d("reciever",e.tostring());         }       }     @override     public void onstart(intent intent, int startid) {         toast.maketext(this, "proximity service started", toast.length_long).show();         //intentfilter filter = new intentfilter(proximitys);         //registerreceiver(mybroadcast,filter);       }     public class proximityintentreceiver extends broadcastreceiver{          private static final int notification_id = 1000;         @override         public void onreceive(context arg0, intent arg1) {             string key = locationmanager.key_proximity_entering;              boolean entering = arg1.getbooleanextra(key, false);             string here = arg1.getextras().getstring("alert");             string happy = arg1.getextras().getstring("type");                 notificationmanager notificationmanager =                          (notificationmanager) getsystemservice(context.notification_service);                      pendingintent pendingintent = pendingintent.getactivity(arg0, 0, arg1, 0);                              notification notification = createnotification();                      notification.setlatesteventinfo(arg0,                          "entering proximity!", "you approaching " + here + " marker.", pendingintent);                      notificationmanager.notify(notification_id, notification);                   }                  private notification createnotification() {                     notification notification = new notification();                      notification.icon = r.drawable.icon;                     notification.when = system.currenttimemillis();                      notification.flags |= notification.flag_auto_cancel;                     notification.flags |= notification.flag_show_lights;                      notification.defaults |= notification.default_vibrate;                     notification.defaults |= notification.default_lights;                      notification.ledargb = color.white;                     notification.ledonms = 1500;                     notification.ledoffms = 1500;                       return notification;                 }             //make actions        }      public class mylocationlistener implements locationlistener {             public void onlocationchanged(location location) {                 toast.maketext(getapplicationcontext(), "i here", toast.length_long).show();             }              public void onproviderdisabled(string s) {             }             public void onproviderenabled(string s) {                         }             @override             public void onstatuschanged(string arg0, int arg1, bundle arg2) {                 // todo auto-generated method stub              }         }  } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -