B4A Library RSProximityAlert - Enter or exit surrounding area

Discussion in 'Additional libraries, classes and official updates' started by XverhelstX, Dec 24, 2013.

  1. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Hi folks

    Yet again a new library called RSProximityAlert.
    There is already one in esLocationManager, but mine will let you add multiple Proximity Alerts to locations instead of 1.

    A proximity alert is a broadcast you receive when the device detects that it has entered or exited the area surrounding the location you entered.

    API Documentation

    Manifest Editor

        <action android:name=
    "com.rootsoft.rslocationmanager.PROXIMITY_ALERT" />

    dim mProximityAlert as RSProximityAlert
    Add a Proximity alert to a location

    Dim pIntent As Object
    pIntent = mProximityAlert.AddProximityAlert(Longitude, Latitude, Radius, PROXIMITY_DEFAULT_EXPIRATION, EventId, EventId)
            mapProximityAlerts.Put(EventId, pIntent)
    Handle the intent in your StartService

    'Handles the intent.
    Private Sub HandleIntent(StartingIntent As Intent)

    If StartingIntent.Action = mProximityAlert.PROXIMITY_INTENT_ACTION Then

            EventId = StartingIntent.GetExtra(mProximityAlert.EVENT_ID_INTENT_EXTRA)
            Entering = StartingIntent.GetExtra(mProximityAlert.KEY_PROXIMITY_ENTERING)
    If Entering Then
    End If
    End If

    End Sub
    'The user is entering a spot.
    Public Sub ProximityEntered (EventId As Long)
    Log("Entering Proximity Area: " & EventId)
    End Sub

    'The user is leaving a spot.
    Public Sub ProximityLeft (EventId As Long)
    Log("Leaving a Proximity Area: " & EventId)

    End Sub
    Removing a Proximity alert can be done by setting the experation or removing the PendingIntent.
    This is why you should save the PendingIntent together with the EventId in a map.

    Kind regards,

    Attached Files:

  2. bluedude

    bluedude Well-Known Member Licensed User

    Interesting, a few questions:

    - What do you mean by handle intent in StartService? Do you mean in a service in the service creation part?
    - how many proximity events can it handle?
    - how to remove a pending intent?

    Would this work with the Fluffy location stuff?

  3. XverhelstX

    XverhelstX Well-Known Member Licensed User

    1. Copy the HandleIntent to your Service_Start sub and pass the StartingIntent parameter.
    A broadcast intent is sent when entering or leaving the proximity.

    2. I have no idea. I think unlimited.

    3. Store the pendingintent in a map with EventId as the key. You can call ProximityAlert.RemoveProximityAlert to remove one.
    Just pass the PendingIntent from the map as parameter

    4. Yes, this is why I ported it as i'm using it in a app of my own.
  4. bluedude

    bluedude Well-Known Member Licensed User

    Mmmm, still a little clueless about how to implement this. The service is started by a broadcast? What is the VirtualService in the manifest? Is this the service I create myself?

    What location solution needs to be implemented to get this working? GPS, WIFI or?

    A sample would help :)
  5. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Yes, whenever the OS finds that you are in that proximity, it will send a broadcast to you own service and starts it (Here VirtualService)
    You can use any location library, and just for any location you find (with GPS for instance _LocationChanged) you can add a proximityalert on that location.

    Just change your manifest.
    Add the handleintent sub in your servce_create sub and adds the ProximityEntered and ProximityLeft subs. These are events when called when leaving or entering the area.
  6. knifenine

    knifenine Member Licensed User

  7. Theera

    Theera Well-Known Member Licensed User

    Hi Tomas,or others
    Where is virtualservice_br Module? I cann't see it.

    Attached Files:

    Last edited: Feb 18, 2014
    deyvitavara likes this.
  8. Filippo

    Filippo Expert Licensed User

    Hi XverhelstX,

    do you have an example that works?
  9. merlin2049er

    merlin2049er Well-Known Member Licensed User

    Hey, cool. I guess this would work if you were to pair it up with a bluetooth beacon.
  10. Croïd

    Croïd Active Member Licensed User


    Please, you have an example to understand the process ?

    How possible put notification near to a destination ?

    Thanks for your help

    Attached Files:

    • rs2.zip
      File size:
      7.7 KB
  11. coslad

    coslad Well-Known Member Licensed User

    HI XverhelstX

    in the add function what do you mean for :

    Expiration As Long ?
    EventID As Long ? We decide the eventid number ?
    RequestCode As Int ?
    Radius As Float ? Is radius in centimeter , meter, km ?

    Thanks !!
  12. coslad

    coslad Well-Known Member Licensed User

    It seems that this library is based on google service? May I wrong?
  13. Croïd

    Croïd Active Member Licensed User

  14. coslad

    coslad Well-Known Member Licensed User

    Thanks for the reply, but seems that whit exlocationmanager you can add a single Geofence location
  15. b4xscripter

    b4xscripter Member Licensed User

    How is everything? Is updated the RSProximityAlert library?
    I would like to use it for my next project.

    Best regards
  16. Danbicky

    Danbicky Member Licensed User

    This sounds Awesome, Please can you post an Example app showing us how to use this. I have an idea to use this for when I arrive home in the car to then send an MQTT message to disarm my alarm system and arm when I leave for work in the morning based on proximity. I have already developed the hardware and can control this through MQTT commands.

    Great work

  17. b4xscripter

    b4xscripter Member Licensed User

    Hi all,
    I resolved it and implemented it in my new project using Fused Location and Node.js (with MongoDB). Works perfectly.
    By basic concerns to not implement all the "proximity logic" in the Android device but on the server are:
    - I am not sure that the multiple alarms are working
    - Sometimes the device be disconnected or even switched off. So the alert would "die". So I implemented the logic on the server and used the Android to "ping" to my server providing the geolocation coordinates...

    If anyone is interested, I would be happy to share my solution.

    Best regards
  18. Danbicky

    Danbicky Member Licensed User

    Hi @

    Would be so cool if you could share your solution.
    Big thanks buddy

  19. Danbicky

    Danbicky Member Licensed User

    Hi XverhelstX

    Do you have a simple example demonstrating how this code works. I would really like to try this out with a Geo zone of 100 metres around my location and to control some device I have based on entering and exiting the Geo zone.

    Big thanks in advance for all your assistance.

  20. DonManfred

    DonManfred Expert Licensed User

    Dont expect an answer from Xverhelst as he is no longer an active user.
    lemonisdead likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice