Android Question GPS and WebView

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello all,

I'm trying to use a webview that access a site which requires the location, but besides I requested and allowed PERMISSION_ACCESS_FINE_LOCATION in the app I'm still getting the message about gps authorization required inside the webview - there is no any pop up to request that also.
Is there any way to allow GPS inside a webview?

Thanks!
 

DonManfred

Expert
Licensed User
Longtime User
did you use webviewextras and also implemented the Permission subs?


Events:
GeolocationPermissionsRequest As Int
ProgressChanged(NewProgress As Int)
ProgressChanged2(WebView1 As WebView, NewProgress As Int)
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
did you use webviewextras and also implemented the Permission subs?

Hello @DonManfred ,

no, I didn't use webViewExtras but I implemented the permission acces_fine_location request and allowed it. I noticed also that GPS in webview requires webChromeClient (here: https://stackoverflow.com/questions/5329662/android-webview-geolocation ) , but I didn't find a complete sample in the community posts. I'll try to write a test code joining the pieces I found and your tip.

Thanks!
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
1. Implement webviewextras and webchromeclient.
2. Implement the Eventsubs needed (see above).
3. Return one of the valid Int (see documentationlink above) in the GeolocationPermissionsRequest event.
Thanks... I'm writing the code and will post here when finished (in a couple minutes I hope :))
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Is this correct ?

B4X:
Sub webChromeClient1_GeolocationPermissionsRequest
    
    Return webChromeClient1.GEOLOCATION_PERMISSION_ALLOW_AND_REMEMBER
    
End Sub

The sub is being triggered but I'm getting the error:

[FATAL:jni_android.cc(249)] Please include Java exception stack in crash report
Fatal signal 5 (SIGTRAP), code -6 (SI_TKILL) in tid 19833 (om.test.webview), pid 19833 (om.test.webview)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Xiaomi/cepheus_eea/cepheus:10/QKQ1.190825.002/V11.0.6.0.QFAEUXM:user/release-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2020-02-10 08:00:33-0300
pid: 19833, tid: 19833, name: om.test.webview >>> com.test.webview <<<
uid: 10297
signal 5 (SIGTRAP), code -6 (SI_TKILL), fault addr --------
Abort message: '[FATAL:jni_android.cc(249)] Please include Java exception stack in crash report
'
x0 0000000000000000 x1 0000000000000081 x2 000000007fffffff x3 0000000000000000
x4 0000000000000000 x5 0000000000000000 x6 0000000000000000 x7 7f7f7f7f7f7f7f7f
x8 0000000000000000 x9 0000000000000000 x10 0000000000000001 x11 0000000000000000
x12 00000071f31cb740 x13 ffffffffffffffff x14 0000000000000004 x15 ffffffffffffffff
x16 0000007302424878 x17 00000073023b1660 x18 00000073068e0000 x19 0000007feda1a0f0
x20 0000007feda1a0f8 x21 0000007feda1a100 x22 000000000000004f x23 000000730241f508
x24 000000722a1c0000 x25 0000007306334020 x26 0000000000000000 x27 0000007feda19c40
x28 000000722a1c1000 x29 0000007feda1a090
sp 0000007feda19c30 lr 0000007227ccbe14 pc 0000007227ccbffc
backtrace:
#00 pc 00000000017d9ffc /data/app/com.google.android.webview-GJj3Qr5ni_YXvff3F9qx3g==/base.apk!libmonochrome.so (offset 0x15b000) (BuildId: 4cc23f5b15670e8d291f94328864b77e0af0387f)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is this correct ?
i would say yes. I need to check if i have a project on my PC using the permission in a webview. Can´t remember though if i build one.

Need to check later.

I´m sure you´ll find an exampe using the forumsearch. You now have the correct keywords to use a search ;-)
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
i would say yes. I need to check if i have a project on my PC using the permission in a webview. Can´t remember though if i build one.

Need to check later.

I´m sure you´ll find an exampe using the forumsearch. You now have the correct keywords to use a search ;-)
Thanks my friend! An update. I changed to:
B4X:
Sub webChromeClient1_GeolocationPermissionsRequest As Int
   
    Return webChromeClient1.GEOLOCATION_PERMISSION_ALLOW_AND_REMEMBER
   
End Sub

Notice the "as int" at the sub declaration... there is no error anymore BUT the site can't get the gps coordinates yet. I'll continue testing . Your help was highly valuable ! Really thanks!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
A full example
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
A full example
I already used this thread some time ago... webView and webViewExtras have many details and javascript, gps, service workers and some web additional features are complicated to integrate in it. Some time ago I was sure that some PWA had problems with webview, but I tested again after Android X and it's working... I'm not sure if I did something wrong or this worked due any new implementation of Android X...
I'll enable the webviewextras debug and check what is happening - and post here to help the community as always.

If you have some additional tip or code and have time, please post here.

Thanks!
 
Upvote 0
Top