Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Android, java, coding problem, can you spot a mistake?

Options
  • 14-04-2009 1:51pm
    #1
    Registered Users Posts: 18,272 ✭✭✭✭


    Its me again, seem to be getting stuck on everything these days!

    I've been developing a small application for Android using maps and proximity alerts but i've hit a problem

    I'm trying to use proximity alerts on my map activity so when someone drives into a car park they know whether they need a disk or to pay for a ticket.

    I have the alerts working properly, however when an alert is fired all the other alerts seem to get fired too, so if the user goes into car park 4 the messages for the other car parks get fired too.

    here is my code

    oncreate
    setProximityAlert(53.984511, -6.395137, "Car Park 1", "You are in a staff/lecturer car park, you must have a valid disk to park here");
          setProximityAlert(53.983862, -6.394853, "Car Park 5", "You are in a staff/lecturer car park, you must have a valid disk to park here");
          setProximityAlert(53.985969, -6.395288, "Car Park 2", "You are in a paid car park, please ensure you have paid for a valid parking ticket for the time you intend to stay parked");
          setProximityAlert(53.986101, -6.394590, "Car Park 3", "You are in a paid car park, please ensure you have paid for a valid parking ticket for the time you intend to stay parked");
          setProximityAlert(53.986350, -6.393346, "Car Park 4", "You are in a paid car park, please ensure you have paid for a valid parking ticket for the time you intend to stay parked");
    


    setproximityalert()
    private void setProximityAlert(double lat, double lng, String title, String text) {
         LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    
        // double lat = 53.984511;
        // double lng = -6.395137;
         float radius = 30f; //meters
         long expiration = -1; //do not expire
        
         Intent intent = new Intent(TREASURE_PROXIMITY_ALERT);
         PendingIntent proximityIntent = PendingIntent.getBroadcast(getApplicationContext(), -1, intent, 0);
         locationManager.addProximityAlert(lat, lng, radius, expiration, proximityIntent);
         
         IntentFilter filter = new IntentFilter(TREASURE_PROXIMITY_ALERT);
         registerReceiver(new ProximityIntentReceiver(title, text), filter);
       }
    

    proximityintentreciever
    public class ProximityIntentReceiver extends BroadcastReceiver {       
    	   Game2 game = new Game2();
    	   
    	   String title;
    	   String text2;
    	  
     	  public ProximityIntentReceiver(String title, String text){
    		   
    		   this.title = title;
    		   this.text2 = text;
    	   }
     	  
     	 @Override
     	  public void onReceive (Context context, Intent intent) {
     	    String key = LocationManager.KEY_PROXIMITY_ENTERING;
     	   Log.d("PROXIMITy KEY ENTER", LocationManager.KEY_PROXIMITY_ENTERING);
    
     	    Boolean entering = intent.getBooleanExtra(key, false);
     	   Dialog d = new Dialog(Game2.this);
     	// Have the new window tint and blur the window it
     	// obscures.
     	Window window = d.getWindow();
     	window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
     	WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
     	d.setTitle(title);
     	d.setContentView(R.layout.dialog_view);
     	TextView text = (TextView)d.findViewById(R.id.dialogTextView);
     	text.setText(text2);
     	    
     	d.show();
     	    //[ ... perform proximity alert actions ... ]
     	  }
       }
    

    Can anyone suggest a better way to set up the proximity alerts so that they dont all fire when when proximity is fired? or point out where the mistake is in my code?


Advertisement