Dec 24, 2013 Replies: 20 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 RSProximityAlert Author: XverhelstX Version: 1 RSProximityAlert Fields: EVENT_ID_INTENT_EXTRA As String KEY_PROXIMITY_ENTERING As String PROXIMITY_INTENT_ACTION As String Methods: AddProximityAlert (Longitude As Double, Latitude As Double, Radius As Float, Expiration As Long, EventID As Long, RequestCode As Int) As PendingIntent Set a proximity alert for the location given by the position (latitude, longitude) and the given radius. When the device detects that it has entered or exited the area surrounding the location, the given PendingIntent will be used to create an Intent to be fired. The fired Intent will have a boolean extra added with key KEY_PROXIMITY_ENTERING. If the value is true, the device is entering the proximity region; if false, it is exiting. Returns the pending intent. Save this intent in a map with the Eventid if you want to remove this ProximityAlert later. Initialize Initializes this RSProximityAlert library IsInitialized As Boolean RemoveProximityAlert (intent As PendingIntent) Removes the Proximity Alert. Permissions: android.permission.ACCESS_COARSE_LOCATION android.permission.ACCESS_FINE_LOCATION Click to expand... Manifest Editor Code: Copy AddReceiverText(VirtualService, <intent-filter> <action android:name="com.rootsoft.rslocationmanager.PROXIMITY_ALERT" /> </intent-filter>) Initialize Code: Copy dim mProximityAlert as RSProximityAlert mProximityAlert.Initialize Add a Proximity alert to a location Code: Copy 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 Code: Copy '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 Code: Copy '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 RSProximityAlert.zip 3.4 KB · Views: 838 Click to expand...
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 RSProximityAlert Author: XverhelstX Version: 1 RSProximityAlert Fields: EVENT_ID_INTENT_EXTRA As String KEY_PROXIMITY_ENTERING As String PROXIMITY_INTENT_ACTION As String Methods: AddProximityAlert (Longitude As Double, Latitude As Double, Radius As Float, Expiration As Long, EventID As Long, RequestCode As Int) As PendingIntent Set a proximity alert for the location given by the position (latitude, longitude) and the given radius. When the device detects that it has entered or exited the area surrounding the location, the given PendingIntent will be used to create an Intent to be fired. The fired Intent will have a boolean extra added with key KEY_PROXIMITY_ENTERING. If the value is true, the device is entering the proximity region; if false, it is exiting. Returns the pending intent. Save this intent in a map with the Eventid if you want to remove this ProximityAlert later. Initialize Initializes this RSProximityAlert library IsInitialized As Boolean RemoveProximityAlert (intent As PendingIntent) Removes the Proximity Alert. Permissions: android.permission.ACCESS_COARSE_LOCATION android.permission.ACCESS_FINE_LOCATION Click to expand... Manifest Editor Code: Copy AddReceiverText(VirtualService, <intent-filter> <action android:name="com.rootsoft.rslocationmanager.PROXIMITY_ALERT" /> </intent-filter>) Initialize Code: Copy dim mProximityAlert as RSProximityAlert mProximityAlert.Initialize Add a Proximity alert to a location Code: Copy 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 Code: Copy '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 Code: Copy '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
D Danbicky Member Licensed User Longtime User Oct 16, 2015 #21 Thanks Don, Can anyone share an example to show me how you get basic operation for the proximity alert. Thanks Dans
Thanks Don, Can anyone share an example to show me how you get basic operation for the proximity alert. Thanks Dans