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 6106487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:05:06+00:00 2026-05-23T14:05:06+00:00

I have specified 2 proximity alerts for 2 different points. For each proximity alert

  • 0

I have specified 2 proximity alerts for 2 different points.
For each proximity alert i have specified an eventID as you can see in the following code. For each proximity alert(for each point) i want differrent notification sound. The main question is how i can create different notifications (notifications sound) within the same class.

Here is the code i have used.

private void setProximityAlert(double lat, double lon, final int eventID,int requestCode) {

            float radius = 10f;         

            long expiration =-1; 
            LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);  
            Bundle extras = new Bundle();                       
            Intent intent = new Intent(PROXIMITY_INTENT_ACTION);                
            intent.putExtra(ProximityAlert.EVENT_ID_INTENT_EXTRA, eventID);
            intent.putExtra(PROXIMITY_INTENT_ACTION, extras); 
            PendingIntent proximityIntent = PendingIntent.getBroadcast(getApplicationContext(), requestCode , intent, PendingIntent.FLAG_CANCEL_CURRENT);

                locManager.addProximityAlert(
                    lat, 
                    lon, 
                    radius, 
                    expiration, 
                    proximityIntent 
               );     
            }

 private void initialiseReceiver()
        {
            IntentFilter filter = new IntentFilter(PROXIMITY_INTENT_ACTION); 
            registerReceiver(new ProximityAlert(), filter);
        }

In the BroadcastReceiver class i have the notification in the following code

public class ProximityAlert extends BroadcastReceiver {

            public static final String EVENT_ID_INTENT_EXTRA = "EventIDIntentExtraKey";




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

                int eventID = intent.getIntExtra(EVENT_ID_INTENT_EXTRA, 1);



                switch(+eventID) {


                case '1':

                    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 = new Notification(); 

                        notification.setLatestEventInfo(context, "Proximity Alert!", "ειναι σωστο αυτο που εκανεσ", pendingIntent);

                        notificationManager.notify(1, notification);

                        notification.icon = R.drawable.ic_menu_notifications;
                        notification.sound =  Uri.parse("file:///sdcard/File/sdcard/introduction_file.mp3");

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

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

                    break;

                case '2':

                    String key1 = LocationManager.KEY_PROXIMITY_ENTERING;

                    Boolean entering1 = intent.getBooleanExtra(key1, false);

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

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

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

                        Notification notification1 = new Notification();    

                        notification1.setLatestEventInfo(context, "Proximity Alert!", "ειναι σωστο αυτο που εκανεσ", pendingIntent1);

                        nnotificationManager.notify(2, notification1);

                        notification1.icon = R.drawable.ic_menu_notifications;
                        notification1.sound =  Uri.parse("file:///sdcard/File/sdcard/Carter_Lane.mp3");

                        notification1.flags |= Notification.FLAG_AUTO_CANCEL;
                        notification1.flags |= Notification.FLAG_INSISTENT;
                        notification1.flags |= Notification.FLAG_ONGOING_EVENT;

                        notification1.ledARGB = Color.WHITE;
                        notification1.ledOnMS = 1500;
                        notification1.ledOffMS = 1500;


                    break;

I have used the switch method so, for different eventID the programme should change notification. but it does not work. can you help me
thank you very much.

  • 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-23T14:05:06+00:00Added an answer on May 23, 2026 at 2:05 pm

    You only have one PendingIntent.

    Quoting the documentation:

    If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid

    Since you have the same operation (getBroadcast()) and the same Intent routing pieces each time, there is only one PendingIntent.

    Rather than setting the action to be PROXIMITY_INTENT_ACTION, make it be unique for each distinct proximity alert. If you use the component constructor on Intent (i.e., new Intent(this, MyReceiver.class)), the different action strings will not impact the routing of the broadcast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although i have specified a unique key, it seems the following code will return
I have follwowing peace of code in which I have specified the leaky line
I have the following column specified in a database: decimal(5,2) How does one interpret
I have a form where I've specified onSubmit=validate() , but I want to ignore
Let's say that I have specified the following WCF REST Service at the address
In my application, I have specified a second activity that can be launched from
I want to parse the strings, so that to check whether they have specified
I am trying to use ehcache in my project.. i have specified the following
I have a plot with pairs of points that are slightly offset. Each pair
I have placed two divs next to each other, I have specified the same

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.