I am creating proximity alerts for dynamically created overlays but I have a problem that the Broadcast receiver doesn't fire when the user moves within the radius.
private void registerIntents() {
for(int i = 0; i < points.size(); i++) {
double intentLat, intentLon;
intentLat = (int)(points.get(i).getLat() * 1E6);
intentLon = (int)(points.get(i).getLon() * 1E6);
setProximityAlert(intentLat, intentLon, i+1,i);
}
}
private void setProximityAlert(double lat, double lon, final long eventID, int requestCode)
{
// 100 meter radius
float radius = 100f;
// Expiration is 10 Minutes (10mins * 60secs * 1000milliSecs)
long expiration = 600000;
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
int uniqueID = requestCode;
String intentAction = PROXIMITY_INTENT_ACTION + uniqueID;
//Intent intent = new Intent(PROXIMITY_INTENT_ACTION);
//intent.putExtra(ProximityAlertReceiver.EVENT_ID_INTENT_EXTRA, eventID);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), uniqueID, new Intent(intentAction), PendingIntent.FLAG_CANCEL_CURRENT);
mIntentFilter = new IntentFilter(intentAction);
locManager.addProximityAlert(lat, lon, radius, expiration, pendingIntent);
}
This is the code for creating the proximity alerts and the following code is for registering the Broadcast Receiver. I have it in the on create method.
this.registerIntents();
registerReceiver(new ProximityAlertReceiver(), mIntentFilter);
I would really appreciate any help with this as I've been working on it for days with no success.
These are the permissions I have in my manifest file.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Try using the PendingIntent that goes directly to your class:
Intent i = new Intent(this, MyActivity.class);
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, i, 0);
This skips the step of going through a BroadcastReceiver and simplifies the code. If you're still not seeing the notifications, then I'd check to make sure the LocationManager is generating any position updates at all.