Cannot get addProximityAlert to work. Intent is never fired.

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Cannot get addProximityAlert to work. Intent is never fired.

Postby mdamen » Wed May 12, 2010 11:03 pm

I'm trying to use addProximityAlert however, this alert is never fired. I can see it getting created in LogCat:

05-12 21:34:23.571: DEBUG/LocationManager(219): addProximityAlert: latitude = 6.287613, longitude = 51.96225, radius = 100.0, expiration = -1, intent = PendingIntent{43d13120: android.os.BinderProxy@43d13028}

However it is never triggered, I am testing this using geo fix command in the AVD console. Even using the exact coordinates doesn't work.

Here is my code, any help is greatly appreciated!

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import android.app.PendingIntent;
  3.  
  4. import android.app.Service;
  5.  
  6. import android.content.BroadcastReceiver;
  7.  
  8. import android.content.Context;
  9.  
  10. import android.content.Intent;
  11.  
  12. import android.content.IntentFilter;
  13.  
  14. import android.location.LocationManager;
  15.  
  16. import android.os.IBinder;
  17.  
  18. import android.util.Log;
  19.  
  20.  
  21.  
  22. public class ProximityChecker extends Service  {
  23.  
  24.         ProximityCheckerReceiver proximityCheckerReceiver;
  25.  
  26.        
  27.  
  28.     protected static final String PROXIMITY_ALERT = new String("android.intent.action.PROXIMITY_ALERT");
  29.  
  30.     protected final IntentFilter proximityFilter = new IntentFilter(PROXIMITY_ALERT);
  31.  
  32.  
  33.  
  34.         public class ProximityCheckerReceiver extends BroadcastReceiver {
  35.  
  36.                 @Override
  37.  
  38.                 public void onReceive(Context context, Intent intent) {
  39.  
  40.                         String intentAction = intent.getAction();
  41.  
  42.                         if (intentAction.equals("android.intent.action.PROXIMITY_ALERT")) {
  43.  
  44.                                 Log.i("TEST", "Received okidoki");
  45.  
  46.                         }
  47.  
  48.                 }
  49.  
  50.         }
  51.  
  52.    
  53.  
  54.         @Override
  55.  
  56.         public void onCreate() {
  57.  
  58.                 super.onCreate();
  59.  
  60.  
  61.  
  62.                 LocationManager pxLocationManager =
  63.  
  64.                         (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  65.  
  66.                
  67.  
  68.                 Intent intent = new Intent(PROXIMITY_ALERT);
  69.  
  70.                 PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, intent , PendingIntent.FLAG_CANCEL_CURRENT);
  71.  
  72.                
  73.  
  74.                 pxLocationManager.addProximityAlert(6.287613, 51.96225, 100f, -1, pendingIntent);
  75.  
  76.                  
  77.  
  78.                 registerReceiver(proximityCheckerReceiver,proximityFilter);
  79.  
  80.  
  81.  
  82.         }
  83.  
  84.        
  85.  
  86.  
  87.  
  88.         @Override
  89.  
  90.         public IBinder onBind(Intent intent) {
  91.  
  92.                 return null;
  93.  
  94.         }
  95.  
  96. }
  97.  
  98.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
mdamen
Freshman
Freshman
 
Posts: 2
Joined: Wed May 12, 2010 11:00 pm

Top

Same Problem.

Postby JamesBecwar » Mon May 17, 2010 2:12 am

I'm having the same problem with the intent never fireing from a service. Did you happen to get it working?
-James
JamesBecwar
Once Poster
Once Poster
 
Posts: 1
Joined: Mon May 17, 2010 1:58 am

Re: Cannot get addProximityAlert to work. Intent is never fi

Postby p6majo » Wed May 19, 2010 7:37 pm

I also face these difficulties. I'm new to the business of broadcasts and receivers but when I just copy the code given above, the proximityCheckerReceiver is null, when it is registered in registerReceiver. It should be initiated somewhere I suppose. I tried it with this substitution:
registerReceiver(new ProximityCheckerReceiver, proximityFilter) but it didn't help a lot after all.
I'm eagerly waiting for a nice solution.

Thx, p6majo
p6majo
Freshman
Freshman
 
Posts: 3
Joined: Thu Sep 10, 2009 7:29 pm

Re: Cannot get addProximityAlert to work. Intent is never fi

Postby ulyan » Wed May 26, 2010 9:14 am

I have read that the -1 might be the problem. Did you try changing it to something else ?

Can you guys explain a bit what does this proximity alert do, I have in mind making the phone vibrate when it enters the radius, you think it's possible as I have no ideea what where to start from :roll: ?!?
ulyan
Freshman
Freshman
 
Posts: 2
Joined: Wed May 26, 2010 7:45 am

Re: Cannot get addProximityAlert to work. Intent is never fi

Postby eaudet@jarics.com » Sat Oct 09, 2010 3:42 am

Try with coordinates 0,0 and fire the same coord using DDMS
eaudet@jarics.com
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Oct 09, 2010 3:40 am

Top

Return to Map Problems

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests