Android Question GPS not Starting in B4XPages

Cliff McKibbin

Member
Licensed User
I am in the process of converting a GPS App to B4XPages.
The logic below to start the GPS is that found in the forum and has been working fine.
I have compiled the original program with B4A V11.0 and it works fine.

The Manifiest entry is the same as that in the forum:
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)

I added log entries to the standard code and they resulted in:

GPS Enabled:true
Permission for fine access requested
*** mainpage: B4XPage_PermissionResult [mainpage]
** Activity (main) Pause event (activity is not paused). **
*** mainpage: B4XPage_Disappear [mainpage]
log ended at this point

As you can see, I never get a log results for "Permission Result", "GPS Start Request..." and "Logic fell through....".
I also note that that I get log entries indicating that B4XMainPage has disappeared which would indicate that it quit while waiting for the permission.

Is there a change required to the standard forum entry for these permissions for B4XPages?
Or, am I missing something else?

Thanks

B4X:
private Sub b4xpage_appear
	B4XPages.SetTitle (Me,"Tour Speed Main Menu")
        Log ("GPS Enabled:" & Starter.GPS1.GPSEnabled)
	If Starter.GPS1.GPSEnabled = False Then
'		ToastMessageShow("Please enable the GPS device.", True)
		StartActivity(Starter.GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
	Else
		Log ("Permission for fine access requested")
		Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
		Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
		Log ("permission Result:" & Result)
		If Result Then 
			Log ("GPS Start request from B4XMainMenu")
			CallSubDelayed(Starter, "StartGPS")
		End If
	End If
	Log ("Logic fell through the Permission request")
 

Peter Simpson

Expert
Licensed User
Longtime User
Hmm,
Try the attached file
 

Attachments

  • GPS.zip
    9.9 KB · Views: 230
Upvote 0

Cliff McKibbin

Member
Licensed User
Thanks Peter and Erel,
Their combined solution as shown below is to bring the GPS start and associated logic into B4XMainPage, thereby eliminating the problem of not 'returning' from the start up in Module 'Starter'.

The new logic is shown below and I had to bring the GPS 'Sensing Change' logic into B4XMainPage as well. These are subs: Sub GPS_LocationChanged (Location1 As Location)
and: Sub GPS_GpsStatus (Satellites As List)

B4X:
Sub Class_Globals

        Public rp As RuntimePermissions
        Public GPS1 As GPS

        '-------------

private Sub b4xpage_appear
 
 GPS1.Initialize("GPS")
	If GPS1.GPSEnabled = False Then
		ToastMessageShow("Please enable the GPS device.", True)
		StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
	Else
		rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
		Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
		If Result Then GPS1.Start(0 , 0)
	End If
 
Upvote 0
Top