Android Question GPS on B4xPages project

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to All
I am converting my "old style" activity based Apps to B4xPages. One of them is using Gps, implemented inside the starter service, as adviced at the time I did it. Now the function of Starter is not so clear (to me). Shall I maintain old code and add starter.bas with Gps functions to the B4xPages project or must I do something different? To be sincere I tried to put the Gps functions directly inside the MainPage, but it seems that the Gps is not responding. In this latter case I missed something, for sure, but the question is whether to insist with this new way, or just use old starter one.
Thanks
 

agraham

Expert
Licensed User
Longtime User
Note the paragraph in bold at the end of the first post here.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Note the paragraph in bold at the end of the first post here.
Yes, forget about Gps. I am using GNSS. I didn't write it here because (wrongly as I see) I thought it was not relevant. The question is whether to maintain the subs that were implemented in Starter, or not.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
One fact is that the followimg code, for some reason, seems not to be executed (either putting Starter functions directly inside B4XPages_Main or not)
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1

    If Starter.GNSS1.GPSEnabled = False Then
        ToastMessageShow("Please enable the GNSS device.", True)
        StartActivity(Starter.GNSS1.LocationSettingsIntent) 'Will open the relevant settings screen.
    Else
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For Activity_PermissionResult (Permission As String, Resu As Boolean)

        If Resu Then
            CallSubDelayed(Starter, "StartGNSS")
        End If
        
    End If
End Sub
In previous version, this code was in Activity_Resume.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The question is whether to maintain the subs that were implemented in Starter, or not.
For me, it depends if you want to make your application cross-platform or not.
If your app remains only for B4A you can leave the subs in the Starter module.
If your app will be cross-platform, i would suggest to move the subs to the B4XMainPage module.

You may have a look at the SQLiteLight examples, those are B4XPages and cross-platform.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
For me, it depends if you want to make you application cross-platform or not.
If your app remains only for B4A you van leave the subs in the Starter module.
If your app will be cross-platform, i would suggest to move the subs to the B4XMainPage module.

You may have a look at the SQLiteLight examples, those are B4XPages and cross-platform.
I just work for "myself", and few poor people using Android.. Good advice, it was what I was asking for. Anyway, as I wrote in previous post, same starter code, added to B4XPages is not working.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
What is not working ?
Can you post a small example project showing the problem ?
My B4xPages code is in previous post here. I just created a standard B4XPages project, without starter. Then I added the Gps functions hereunder, directly to B4xPages_MainPage, taking away the "Starter." references, of course. Nothing else. Having no result, I added the starter.bas module. With "no result" I mean that neither the Log or the ToastMessages appear. The starter is this:
B4X:
#Region  Service Attributes 
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region


Sub Process_Globals
    Public rp As RuntimePermissions
    Public GNSS1 As GNSS
    Private gpsStarted As Boolean
End Sub

Sub Service_Create
    GNSS1.Initialize("GNSS")
End Sub


Sub Service_Start (StartingIntent As Intent)
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy
    StopGNSS
End Sub

Public Sub StartGNSS
    If gpsStarted = False Then
        GNSS1.Start(0, 0)
        gpsStarted = True
    End If
End Sub

Public Sub StopGNSS
    Log("StopGNSS")
    If gpsStarted Then
        GNSS1.Stop
        gpsStarted = False
    End If
End Sub

Sub GNSS_LocationChanged (Location1 As Location)
    Log("LocationChanged:" & Location1.Latitude & ";" & Location1.Longitude)
End Sub

[/code}
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Attached a perfectly not working project... Step by step, my friend, is not useful, when appear "delegates etc.." I don't see where to step in .. unluckily.. Probably I am missing something, of course.. Maybe I did it in a hurry...
 

Attachments

  • TestGps.zip
    10.3 KB · Views: 71
Upvote 0

klaus

Expert
Licensed User
Longtime User
I have looked at your project. To find if it does work i added two labels to display the latitude and longitude.
And i added a LocationChanged sub in B4XMainPage, and modified the call in the GNSS_LocationChanged routine in the Starter.
Attached a perfectly working project.
 

Attachments

  • TestGpsNew.zip
    10.7 KB · Views: 107
Upvote 1

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
I have looked at your project. To find if it does work i added two labels to display the latitude and longitude.
And i added a LocationChanged sub in B4XMainPage, and modified the call in the GNSS_LocationChanged routine in the Starter.
And it works.
I was happy that you wrote that it worked and marked the solution button... Nevertheless, no, not in my case. The app asks whether to activate Gps, I say yes (of course) but nothing appears ..
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Ok. I verified that things are as you say. The strange is that I never had such a problem before, working in same location. It may be a temporary situation that fooled me. Yes, your example works. Thanks a lot
 
Upvote 0
Top