Android Question WebView with Upload File and Geolocation

Foz

Member
Licensed User
Longtime User
Thanks to Erel and his code here:
https://www.b4x.com/android/forum/threads/webviewextras.12453/#post-102448

This enabled the webview to upload files. However, I also need the geolocation functionality. No problem, I added this to the MyChromeClient:
B4X:
   @Override
   public void onGeolocationPermissionsShowPrompt(String origin,
            GeolocationPermissions.Callback callback) {
           callback.invoke(origin, true, true);
   }
and I added to the manifest
B4X:
AddPermission(android.permission.ACCESS_FINE_LOCATION)

However when I check on getting the geolocation, it doesn't seem to call the onGeolocationPermissionsShowPrompt, and a call for getting the geolocation just fails.

Am I missing something else?
 

Attachments

  • Example.zip
    4.2 KB · Views: 319

Foz

Member
Licensed User
Longtime User
Hi, sorry for the delay with Easter and all that.

You are quite correct, I copied and pasted the wrong link - sorry about that!

I'm not using rp.CheckAndRequest - I thought that just calling the callback with the parameters set to true would automatically grant the permissions, but it doesn't.

I added a CheckAndRequest that is called on Activity_Resume, and I added the WebViewSetting library and set the setGeolocationEnabled to true, and the webpage now displays "Waiting on browser", and the Toast displays that the result of the check is true, but it gets no further.

What else do I need to change/add to allow the geolocation to work?
 

Attachments

  • Example.zip
    4.4 KB · Views: 323
Upvote 0

Foz

Member
Licensed User
Longtime User
Okay, this is just weird... trying to get to the bottom of the lack of location, I've added the GPS library and I have that updating, so I can see there is a lat long being returned.

I moved the code to a local file, and gave it a few more outputs so I could see where it was getting up to, and a reload so I could retry getting the location.

But the webview just refuses to return a location... I'm obviously missing something, but I don't know what :/
 

Attachments

  • Example.zip
    6.2 KB · Views: 291
Upvote 0

Foz

Member
Licensed User
Longtime User
Why are you using WebView to get the location?.
It's a stop gap solution while I'm recreating their website in an app, which needs file uploads and getting the users current location. It'll take me at least a month to do, but they need an Android app immediately, due to the website falling behind schedule.

Yes, I know it's a dirty solution, but I want to buy some breathing room for the actual solution.

I had figured that a webview container app would be a quickest solution, as getting the current location is the only thing that is missing.
 
Upvote 0
Top