B4A Library RSProximityAlert - Enter or exit surrounding area

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

B4X:
AddReceiverText(VirtualService,
<intent-filter>
    <action android:name="com.rootsoft.rslocationmanager.PROXIMITY_ALERT" />
</intent-filter>)

Initialize

B4X:
dim mProximityAlert as RSProximityAlert
mProximityAlert.Initialize

Add a Proximity alert to a location

B4X:
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

B4X:
'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
            ProximityEntered(EventId)
        Else
            ProximityLeft(EventId)
        End If
      
    End If

End Sub

B4X:
'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,
Tomas
 

Attachments

  • RSProximityAlert.zip
    3.4 KB · Views: 530

Danbicky

Member
Licensed User
Longtime User
Thanks Don,

Can anyone share an example to show me how you get basic operation for the proximity alert.

Thanks

Dans
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…