I recently started working on proximity alerts App. This basically changes the ringtone profile (just vibrate or ringtone intially) based on the users GPS location. I completed the coding part. On "enter" and "exit" Proximity alerts are getting fired and the code in registered BroadcastReceiver is been executing. Till this point it is fine. Actual problem is as follows, (with my sample code lines)
I registered one broadcastreceiver for two Intent actions. Those Intent actions are declared as below, public static final String INTENT_ACTION1 = "org.droidmania.action.PROXIMITYALERT"; public static final String INTENT_ACTION2 = "org.droidmania.action.PROXIMITYALERT2";
And PendingIntent part is as,
private void setProximityAlerts(String intentAction){ Intent intent = new Intent(); intent.setAction(intentAction); //in case the call comes from HomeActivity intentAction will be INTENT_ACTION1 else INTENT_ACTION2
PendingIntent pIntent = PendingIntent.getBroascast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.addProximityAlert(latitude,longitude, vRadius, -1,pIntent); }
Now the BroadcastReceiver code,
class ProxyReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context,Intent intent){
boolean isEnter = intent.getBooleanExtra(KEY_PROXIMITY_ENTERING,false);
if(isEnter){
**//if user is in Home location**
if(intent.getAction().equals(INTENT_ACTION1)){
give the notification that user is in home area
}
**//if user is in Office location**
if(intent.getAction().equals(INTENT_ACTION2)){
give the notification that user is in office area
}
}
else{
//if user is out of Home location
if(intent.getAction().equals(INTENT_ACTION1)){
give the notification that user is out of home area
}
//if user is out of Office location
if(intent.getAction().equals(INTENT_ACTION2)){
give the notification that user is out of office area
}
}
}
This is the way I tested it on my mobile device,
In home I set the gps location with 10m radius. It gave me notification that "user is in home area"
It shown "user exited the home area" message when I am out of that radius.
Now when I am in office I set the gps location with 5m radius. So It gave me notification that "user is in office area". But here I am facing the actual problem as It is showing both "home area entered" and "office area entered" and "home area exited " and "office area exited" messages for every 2 or 1 minute(s) gap. I am not getting why it is happening. (Even I am not moving around after I set the office location GPS..just staying there in the same point......sitting in my office desk seat...)
Am I missing or giving something extra here? Why the alerts are occuring for home proximity as it's been long time since I exited the home area?
Guys please help me out (It's been already 2 weeks of time I spent :-( ). Your help is appreciated.
Thanks.