What's the trick to making ProximityAlerts work?

by Faber Fedor » Sun, 08 Mar 2009 08:14:04 GMT

Sponsored Links
 I think I'm doing everything right wrt ProximityAlerts but I only get
notified in about 1 in a 100 times.

When I switch to Map Mode in my app, I gt a list of locations, map them and
send each one as a ProximityAlert via this code:

                  Intent intent = new Intent(TYW_PROXIMITY_ALERT);
                  PendingIntent proximityIntent =
PendingIntent.getBroadcast(MainMap.this, 1000, intent, 0) ;
                  myLocationManager.addProximityAlert(dLat, dLong,
proximityRadius, 100000000, proximityIntent);
                  Log.i(TAG, "Added ProximityIntent for" + ""+dLat +","+

I have an IntentReceiver setup like this:

   public class ProximityIntentReceiver extends BroadcastReceiver {

        public void onReceive (Context context, Intent intent) {

            String intentAction = intent.getAction();
           // stuff about Vibrators and Notifications elided

I set up an IntentFilter programmatically:

    private void setIntentFilters() {
        IntentFilter proxFilter = new IntentFilter(TYW_PROXIMITY_ALERT);
        registerReceiver(new ProximityIntentReceiver(), proxFilter);

which I call in onCreate().

I've set the minimum distance/time to check for updates to be ridiculously
low (10 feet, 5 secs, 0 for each, etc.).

I assumed I didn't actually have to move to see a ProximityAlert fired but
maybe I do, so today I set up three PAs and walked right past the
locations.  The GPS followed right along but I never got a Notification.

What's the magic to get it to work?  Or does it work in some manner I don't
yet grok?


Faber Fedor
Linux New Jersey


What's the trick to making ProximityAlerts work?

by Mark Murphy » Sun, 08 Mar 2009 08:29:20 GMT


That may be your problem.

You want proximityRadius to be *big*, not small. A 10-foot proximity
radius means you need to be within 10 feet of the target location before
you will get an alert.

Also, FWIW, the radius is in meters.

Mark Murphy (a Commons Guy)
Android Training in Sweden --  http://www.sotrium.com/training.php 


Sponsored Links

Other Threads

1. how to create int[] array containing blading colors


i need to create int array containing two blading colors - e.g. for
green and red:

arr[0] == 0xff00ff00 // green
arr[1] == 0xff11ee00
arr[2] == 0xff22dd00
arr[3] == 0xff33cc00
arr[arr.length - 1] == 0xffff0000 // red

i couldn't find any API for creating such an array, so i used

created GradientDrawable, set its bounds to setBounds(0, 0, 100, 1)
then created Bitmap 100 x 1, drew GradientDrawable on this Bitmap and
finally gotPixels() from Bitmap

is there any more simple way?



2. Alarm Wake Lock and Services

Hello, I have a question about alarms used with services with regards
to wake locks. The documentation explains the behavior using
BroadcastReceivers, a wakelock is held during onReceive(), but doesn't
describe the behavior for alarms starting services with the RTC_WAKEUP
flag. What is the behavior in this case?

I have an app implementing this, an alarm is created with the
RTC_WAKEUP flag that starts a service. The service onCreate() then
starts a thread to do some network activity. It seems to work just
fine but I just want to make sure that I don't need to explicity hold
a wakelock myself.


3. Nasib Roger Dream dan Magic

4. How to use the dpad button to pause and play audio while the device is locked

5. Select image resource dynamically

6. Upgrade official Magic

7. Wipe?