Android Question I'm building a webview app. I need to access the location in my web. How do I get permission for that?

Erel

B4X founder
Staff member
Licensed User
Longtime User
Full example, depends on WebViewExtras2:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private WebView1 As WebView
    Private WebViewExtra As WebViewExtras
    Private Chrome As DefaultWebChromeClient
    Private LocationPermisison As Boolean
End Sub


Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Chrome.Initialize("chrome")
    WebViewExtra.Initialize(WebView1)
    WebViewExtra.SetWebChromeClient(Chrome)
    WebView1.LoadUrl("https://www.openstreetmap.org")
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
    If rp.Check(rp.PERMISSION_ACCESS_FINE_LOCATION) Or rp.Check(rp.PERMISSION_ACCESS_COARSE_LOCATION) Then
        LocationPermisison = True
    End If
End Sub

Private Sub Chrome_GeoLocationPermissionsRequest As Int
    Log("Chrome_GeoLocationPermissionsRequest")
    Return IIf(LocationPermisison, Chrome.GEOLOCATION_PERMISSION_ALLOW_AND_REMEMBER, Chrome.GEOLOCATION_PERMISSION_DISALLOW_AND_REMEMBER)
End Sub

And manifest editor:
B4X:
AddPermission(android.permission.ACCESS_FINE_LOCATION)
 
Upvote 0
Top