Android Question Gnss Library. Error when targetSdkVersion > 30

Juan Vargas (Bioagro)

Member
Licensed User
This library is intended to replace the Gps one.
I run the sample with targetSdkVersion = 33, no GPS library was selected and still I get the error:

java.lang.UnsupportedOperationException: GpsStatus APIs not supported, please use GnssStatus APIs instead


Main:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: GNSS Demo
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
#End Region
#BridgeLogger: true
Sub Process_Globals
    
End Sub

Sub Globals
    Dim lblLon As Label
    Dim lblLat As Label
    Dim lblSpeed As Label
    Dim lblSatellites As Label
    Private lblGnssStatus As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub Activity_Resume
    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, Result As Boolean)
        If Result Then CallSubDelayed(Starter, "StartGNSS")
    End If
End Sub
    

Sub Activity_Pause (UserClosed As Boolean)
    CallSubDelayed(Starter, "StopGNSS")
End Sub


Public Sub GnssStatus (Status As GnssStatus)
    Dim NumberOfSatellites As Int = Status.SatelliteCount
    Dim Beidou, Galileo, Glonass, Gps, Other As List
    Beidou.Initialize
    Galileo.Initialize
    Glonass.Initialize
    Gps.Initialize
    Other.Initialize   
    Dim usedinfix As Int = 0
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("GNSS Status").Append(CRLF)
    For i = 0 To NumberOfSatellites - 1
        Select Status.ConstellationType(i)
            Case Status.CONSTELLATION_BEIDOU
                Beidou.Add(i)
            Case Status.CONSTELLATION_GALILEO
                Galileo.Add(i)
            Case Status.CONSTELLATION_GLONASS
                Glonass.Add(i)
            Case Status.CONSTELLATION_GPS
                Gps.Add(i)
            Case Else
                Other.Add(i)
        End Select   
        If Status.UsedInFix(i) Then usedinfix = usedinfix + 1   
    Next
    sb.Append($"Beidou ${Beidou.Size} : "$)
    For i = 0 To Beidou.Size -1
        sb.Append(Status.Svid(Beidou.Get(i))).Append(" ")
    Next
    sb.Append(CRLF)
    
    sb.Append($"Galileo ${Galileo.Size} : "$)
    For i = 0 To Galileo.Size -1
        sb.Append(Status.Svid(Galileo.Get(i))).Append(" ")
    Next
    sb.Append(CRLF)   
    
    sb.Append($"Glonass ${Glonass.Size} : "$)
    For i = 0 To Glonass.Size -1
        sb.Append(Status.Svid(Glonass.Get(i))).Append(" ")
    Next
    sb.Append(CRLF)   
    
    sb.Append($"Gps ${Gps.Size} : "$)
    For i = 0 To Gps.Size -1
        sb.Append(Status.Svid(Gps.Get(i))).Append(" ")       
    Next
    sb.Append(CRLF)
    
    sb.Append($"Others : ${Other.Size}"$).Append(CRLF)
    sb.Append($"Satellites : ${NumberOfSatellites}"$).Append(CRLF)
    sb.Append($"Used in fix: ${usedinfix}"$).Append(CRLF)
    lblGnssStatus.Text = sb.ToString
End Sub

Public Sub LocationChanged(Location1 As Location)
    lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
    lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
    lblSpeed.Text = $"Speed = $1.2{Location1.Speed} m/s "$
End Sub


Starter:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

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

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

Sub Service_Start (StartingIntent As Intent)

End Sub

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
    If gpsStarted Then
        GNSS1.Stop
        gpsStarted = False
    End If
End Sub

Sub GNSS_LocationChanged (Location1 As Location)
    CallSub2(Main, "LocationChanged", Location1)
End Sub


Sub GNSS_GpsStatus (Satellites As List)
    CallSub2(Main, "GnssStatus", Satellites)
End Sub


Private Sub GNSS_GNSSStatus (Status As GnssStatus)
    CallSub2(Main, "GnssStatus", Status)
End Sub
 
Top