Android: Using html5 to determine geolocation in webview with javascript api

前端 未结 4 1973
孤独总比滥情好
孤独总比滥情好 2020-12-08 17:34

I\'m currently having an issue with geolocation in a webview. I have a webapp. I\'m currently not using phonegap or any other mobile framework. I\'ve been unsuccessful at ge

4条回答
  •  余生分开走
    2020-12-08 18:00

    Add onGeolocationPermissionsShowPrompt() to MyChromeWebViewClient as below:

    private class MyChromeWebViewClient extends WebChromeClient {
    
        @Override
        public void onProgressChanged(WebView view, int progress) {
            // Activities and WebViews measure progress with different scales.
            // The progress meter will automatically disappear when we reach 100%
            activity.setProgress(progress * 100);
        }
    
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            Log.d(LOG_TAG, message);
            // This shows the dialog box.  This can be commented out for dev
            AlertDialog.Builder alertBldr = new AlertDialog.Builder(activity);
            alertBldr.setMessage(message);
            alertBldr.setTitle("Alert");
            alertBldr.show();
            result.confirm();
            return true;
        }
    
        public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
            callback.invoke(origin, true, false);
        }
    }
    

    You need to import "android.webkit.GeolocationPermissions".

    Add this permission:

    
    

    This will work I guess.

提交回复
热议问题