Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3938580
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:12:03+00:00 2026-05-20T00:12:03+00:00

I am trying to create multiple proximity alerts but I cant get it to

  • 0

I am trying to create multiple proximity alerts but I cant get it to work…

I think that the broadcast receiver gets overwritten and thus is handling only the last broadcast. So if I had two points close by only the one whose intent was created last will generate an alert…

I read that I should use request codes but I have no idea on how to do that…


My method for setting up the pending intents and the broadcast receiver…

private void addProximityAlert(double latitude, double longitude, String poiName, String intentfilter) {

    Bundle extras = new Bundle();
    extras.putString("name", poiName);
    Intent intent = new Intent(PROX_ALERT_INTENT+poiName);  
    intent.putExtras(extras);       
    PendingIntent proximityIntent = PendingIntent.getBroadcast(MainMenu.this, requestCode, intent, 0);
    locationManager.addProximityAlert(
        latitude, // the latitude of the central point of the alert region
        longitude, // the longitude of the central point of the alert region
        POINT_RADIUS, // the radius of the central point of the alert region, in meters
        PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration 
        proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
   );
    requestCode++;
   IntentFilter filter = new IntentFilter(intentfilter); 
   registerReceiver(new ProximityIntentReceiver(), filter);
}

My broadcastreceiver class

public class ProximityIntentReceiver extends BroadcastReceiver {

private static final int NOTIFICATION_ID = 1000;

@Override
public void onReceive(Context context, Intent intent) {

    String key = LocationManager.KEY_PROXIMITY_ENTERING;

    Boolean entering = intent.getBooleanExtra(key, false);

    if (entering) {
        Log.d(getClass().getSimpleName(), "entering");
    }
    else {
        Log.d(getClass().getSimpleName(), "exiting");
    }

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, null, 0);        

    Notification notification = createNotification();        
    notification.setLatestEventInfo(context, 
        "Proximity Alert!", "You are approaching: " +intent.getExtras().get("name"), pendingIntent);     
                                                                        //here-------------------------------------
    notificationManager.notify(NOTIFICATION_ID, notification);

}

private Notification createNotification() {
    Notification notification = new Notification();

    notification.icon = R.drawable.androidmarker;
    notification.when = System.currentTimeMillis();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;        
    notification.flags |= Notification.FLAG_INSISTENT;

    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.defaults |= Notification.DEFAULT_SOUND;

    notification.ledARGB = Color.WHITE;
    notification.ledOnMS = 300;
    notification.ledOffMS = 1500;

    return notification;
}

}

Can you please help me??? I’m really stuck with this…

Any help would be really appreciated!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:12:04+00:00Added an answer on May 20, 2026 at 12:12 am

    i got it working after all…

    Exactly what I was looking for: http://www.gauntface.co.uk/blog/2010/01/04/proximity-alerts-in-android/

    Modifications I made


    private void addProximityAlert(double latitude, double longitude, String poiName) {
    
        Bundle extras = new Bundle();
        extras.putString("name", poiName);
        extras.putInt("id", requestCode);
        Intent intent = new Intent(PROX_ALERT_INTENT);
        intent.putExtra(PROX_ALERT_INTENT, extras);
        PendingIntent proximityIntent = PendingIntent.getBroadcast(MainMenu.this, requestCode , intent, PendingIntent.FLAG_CANCEL_CURRENT);
        locationManager.addProximityAlert(
            latitude, // the latitude of the central point of the alert region
            longitude, // the longitude of the central point of the alert region
            POINT_RADIUS, // the radius of the central point of the alert region, in meters
            PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration 
            proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
       );
        requestCode++;       
    }
    
    private void initializeReceiver()
    {
        IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT); 
        registerReceiver(new ProximityIntentReceiver(), filter);
    }
    

    package michaels.pack;
    
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.graphics.Color;
    import android.location.LocationManager;
    import android.util.Log;
    
    public class ProximityIntentReceiver extends BroadcastReceiver {
    
    private static final int NOTIFICATION_ID = 1000;
    
    @Override
    public void onReceive(Context context, Intent intent) {
    
        String key = LocationManager.KEY_PROXIMITY_ENTERING;
    
        Boolean entering = intent.getBooleanExtra(key, false);
    
        if (entering) {
            Log.d(getClass().getSimpleName(), "entering receiverrrrrrrrrrrrrrrrrr");
        }
        else {
            Log.d(getClass().getSimpleName(), "exiting");
        }
    
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, null, 0);        
    
        Notification notification = createNotification();        
        notification.setLatestEventInfo(context, 
            "Proximity Alert!", "You are approaching: " +intent.getBundleExtra("michaels.pack.ProximityAlert.").get("name"), pendingIntent);     
                                                                            //here-------------------------------------
        notificationManager.notify( intent.getBundleExtra("michaels.pack.ProximityAlert.").getInt("id"), notification);
    
    }
    
    private Notification createNotification() {
        Notification notification = new Notification();
    
        notification.icon = R.drawable.androidmarker;
        notification.when = System.currentTimeMillis();
    
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;                
    
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        notification.defaults |= Notification.DEFAULT_SOUND;
    
        notification.ledARGB = Color.WHITE;
        notification.ledOnMS = 300;
        notification.ledOffMS = 1500;
    
        return notification;
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a target which matches multiple directories, but no files. Is
I am trying to create a method that accepts multiple types of controls -
I'm trying to create an app that multiple users would log into a server
I'm trying to create a script that takes a .txt file with multiple lines
I'm trying to create multiple buttons that each one of them doing something. It
I am trying to create multiple processes using fork() and execvp() calls, but so
I am trying to create multiple linear layouts inside main LinearLayout. But i am
I am trying to create multiple shortcuts to my application that pass different arguments
I'm trying to create a MySQL function with multiple inputs, but keep getting an
I am trying to create multiple records with two collections that i have View

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.