android webview 获取geolocation

1.permission

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>



2.

            webview = (WebView) findViewById(R.id.。。。);
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setPluginsEnabled(true);
            webview.setWebViewClient(new BirtMobileWebViewClient());

            webview.getSettings().setGeolocationEnabled(true);
            webview.getSettings()
                    .setJavaScriptCanOpenWindowsAutomatically(true);
            webview.setWebChromeClient(new GeoClient());

3. 其中:

    class GeoClient extends WebChromeClient {

        @Override
        public void onGeolocationPermissionsShowPrompt(String origin,
                android.webkit.GeolocationPermissions.Callback callback) {
            super.onGeolocationPermissionsShowPrompt(origin, callback);
            callback.invoke(origin, true, false);
        }

        // @Override
        // public boolean onJsAlert(WebView view, String url,
        // String message, JsResult result) {
        //
        // AlertDialog.Builder b2 = new
        // AlertDialog.Builder(DetailViewControlerImpl.this)
        // .setTitle("alert").setMessage(message)
        // .setPositiveButton("ok",
        // new AlertDialog.OnClickListener() {
        // @Override
        // public void onClick(DialogInterface dialog,
        // int which) {
        // // result.confirm();
        // // MyWebView.this.finish();
        // }
        // });
        //
        // b2.setCancelable(true);
        // b2.create();
        // b2.show();
        //
        // return true;
        // }

    }



你可能感兴趣的:(android,String,url,Class,dialog,callback)