Notification Help

HimeAnator

Member
Licensed User
Longtime User
I have been looking at the twitter rss feed tutorial and the page on service modules but I just cant seem to wrap my head around the code enough to accomplish what im trying to do. Basically Im trying to create an app that saves the current location using using two text files...
B4X:
File.WriteString(File.DirInternal, "LAT.txt",location2.ConvertToMinutes(location2.Latitude))
   File.WriteString(File.DirInternal, "LONG.txt",location2.ConvertToMinutes(location2.Longitude))

I would like to show a notification on the users phone when ever the phone leaves a 75 yard radius of the recorded Long and Lat. Any help on how I can accomplish this would be much appreciated :sign0104:
 

melamoud

Active Member
Licensed User
Longtime User
Are you asking:
1. Help on how to put something in the notification?
2. Help on location extraction
3. Or help on how to calculate the distance ?
 
Upvote 0

HimeAnator

Member
Licensed User
Longtime User
Yes that library seems to be exactly what I'm looking for. I'm getting closer to getting this to work but I think I'm still having problems implementing the code properly. I hope its alright if I go ahead and post some more code up here to show you what I have going on.

I have created this sub...
B4X:
Sub addProximityAlert (Radius As Int, Lat As Double, Longitude As Double, Life As Long)

End Sub

and added the following code to grab the LAT and LONG and set up a toggle button for the user to turn the service on...

B4X:
Sub GPS_LocationChanged (Location1 As Location)
label2.Text = Location1.ConvertToMinutes(Location1.Latitude)
label3.Text = Location1.ConvertToMinutes(Location1.Longitude)
   
End Sub


Sub togglebutt_CheckedChange(Checked As Boolean)
   If togglebutt.Checked = True Then
   
   Dim location2 As Location

   End If
   
   If signal= True Then 'Detects if valid GPS signal is present
   
   Dim LatValue = label2.text
   Dim LongValue = label3.text
   
   If GPS1.GPSEnabled = False Then
      togglebutt.Checked = False
      ToastMessageShow("Please enable the GPS.", True)
      StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
   Else
      GPS1.Start(0, 0) 'Listen to GPS with no filters.
      togglebutt.Checked = True
      ToastMessageShow("Location saved.", True)
      
      'Starts Alert????????? (receive error about not being a double here)
      addProximityAlert(60,LatValue,LongValue,-1)
   End If
   
   
   Else
   ToastMessageShow("Please wait for a GPS signal.", True)
   togglebutt.Checked=False
   End If

This is what I have going on so far. I apologize if it is a complete mess. I'm mainly a VB.NET programmer so some of the syntax is a little new for me. I also saw something on the page you posted that said, "Proximityexit_Location" so I'm guessing that would be important to add as well but not sure what the proper syntax/implementation would be. Again thank you for any help, I'm about to go bald from all of the hair pulling I'm doing :BangHead:
 
Last edited:
Upvote 0

HimeAnator

Member
Licensed User
Longtime User
Are you asking:
1. Help on how to put something in the notification?
2. Help on location extraction
3. Or help on how to calculate the distance ?

Basically what I want to do is when the user clicks the toggle button to turn on my service. I want the phone to save the current location and then if the user goes 60 meters from the saved location I then would like the phone to alert/notify the user telling them they left the radius.
 
Last edited:
Upvote 0

HimeAnator

Member
Licensed User
Longtime User
There are several examples in the forum of calculating distances between two points.

The proximity alert seems to be what I'm looking for if I want to alert the user that they are leaving an area. Are There any code examples for the proximity alert? I think if I get that set up correctly then I will be fine.
 
Last edited:
Upvote 0

lagore

Active Member
Licensed User
Longtime User
Declare the location object in Globals
B4X:
Dim MyLocation As ESLocation2
initilise the location object
B4X:
MyLocation.Initialize("Location")
to start the proximity alert
B4X:
MyLocation.addProximityAlert(185,53.5123252869,-6.5091342926,-1)
the two subs required to receive the event are
B4X:
Sub Location_Proximityenter ()
   Msgbox("Proximity Alert", "Entering Proximity")
End Sub

Sub Location_Proximityexit ()
   Msgbox("Proximity Alert", "Leaving Proximity")
End Sub
The between the two subs is whether you are going toward or away from the coordinate point.
 
Upvote 0

HimeAnator

Member
Licensed User
Longtime User
How can I get this code to keep running and checking the proximity when the user goes to the home screen or puts there phone to sleep? I currently have a notification that stays on the phone when the program is turned on so I added to the Sub Service_Start
B4X:
Main.MyLocation.addProximityAlert(Main.meters,Main.Lat,Main.Long,-1)

and I also added this sub

B4X:
Sub Location_Proximityexit ()
                Msgbox("You left the proximity")
         
      Notification2.SetInfo(Main.NotifyText, "", Main)
      Notification2.Icon = "icon"
      Notification2.light=True
      Notification2.Sound = True
      Notification2.insistent=True   
      Notification2.vibrate=True
      Notification2.Notify(2)
      
End Sub

Adding that didn't work when I hit the home button/put the phone to sleep. Any ideas?
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
It should have
1. have you called Initialize on the notification object ?
2. have you look at the logs to see if you got any error ?
3. I suggest you move staff like notifyText to the service, have the activity update the service and not the other way around because the service is the live one (it should work either way btw)
 
Upvote 0

romario11

Member
Licensed User
Longtime User
I got it thank you for your help! I had to declare a new addProximityAlert in the service instead of pull the one from the Main module.

hei,
can you know if is possible set some numbers of proximityAlert ? and how i can identify every alert ?
 
Upvote 0
Top