Android Question WebView with Upload File and Geolocation

Discussion in 'Android Questions' started by Foz, Apr 18, 2019.

  1. Foz

    Foz Member Licensed 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:
    Code:
    @Override
       
    public void onGeolocationPermissionsShowPrompt(String origin,
                GeolocationPermissions.Callback callback) {
               callback.invoke(origin, 
    truetrue);
       
    }
    and I added to the manifest
    Code:
    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?
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Foz

    Foz Member Licensed 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?
     

    Attached Files:

  4. Foz

    Foz Member Licensed 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 :/
     

    Attached Files:

  5. Erel

    Erel Administrator Staff Member Licensed User

    Why are you using WebView to get the location? There are much simpler and better ways to do it.
     
  6. Foz

    Foz Member Licensed User

    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.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Get the location with FusedLocationProvider and send it to the server.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice