how to give coordinates to an android emulator to get proximity alert -
i trying implement android simple code uses proximityalerts , gives alert when entering , exiting defined area
the code runs without errors test if works coordinates (first not in area, goes in should receive alert, exits , receive alert) googled how use telnet give lat,long found giving fixed values
is there way approach this? ps: using android studio :)
edit: figured out how change coordinates , followed tutorial proximity test ... code runs without errors intent give alert not seem fire here code: mainactivity
public class mainactivity extends actionbaractivity { locationmanager lm; double lat=32.001271,long1=35.950375; //defining latitude & longitude float radius=100; //defining radius @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); lm=(locationmanager) getsystemservice(location_service); intent i= new intent("com.example.hala.proximityalert"); //custom action pendingintent pi = pendingintent.getbroadcast(getapplicationcontext(), -1, i, 0); lm.addproximityalert(lat, long1, radius, -1, pi); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
proximityreceiver
public class proximityreceiver extends broadcastreceiver { @override public void onreceive(context arg0, intent arg1) { // todo auto-generated method stub // reciever gets context & intent fired broadcast arg0 & agr1 string k=locationmanager.key_proximity_entering; // key determining whether user leaving or entering boolean state=arg1.getbooleanextra(k, false); //gives whether user entering or leaving in boolean form if(state){ // call notification service or else here toast.maketext(arg0, "welcome area", toast.length_long).show(); }else{ //other custom notification toast.maketext(arg0, "thank visiting area,come again !!", toast.length_long).show(); } } }
so if has idea on why doesn't fire appreciate help
you can give coordinates via :
eclipse -> ddms -> emulator control tab -> give coordinate includes latitude , longitude
Comments
Post a Comment