android webview 擷取Geolocation

來源:互聯網
上載者:User

標籤:geolocation   ongeolocationpermiss   webchromeclient   

    <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"/>


private WebViewwebView =null;

private WebSettingswebSettings =null;


private void initWeb() {

webView = (WebView)this.findViewById(R.id.webView_load);

webView.getSettings().setJavaScriptEnabled(true);

loadURL(urlStr);

setClient();

webSettings =webView.getSettings();// 網頁設定預設屬性

webView.setInitialScale(39);// 適應豎屏

webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);// 去掉底部和右邊的捲軸

// webSettings.setRenderPriority(RenderPriority.HIGH);// 提高渲染優先順序

webSettings.setJavaScriptEnabled(true);// 設定是否可以互動Javascript

webSettings.setAllowFileAccess(true);// 啟用或禁止WebView訪問檔案資料

webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);// 設定顯示模式

webSettings.setDefaultZoom(ZoomDensity.MEDIUM);// 適應螢幕

// webView.getSettings().setUseWideViewPort(true);// 是否任意比例縮放

webView.getSettings().setLoadWithOverviewMode(true);// 縮放至螢幕的大小

// webView.getSettings().setUseWideViewPort(true);// 是否任意比例縮放

webSettings.setBuiltInZoomControls(false);// 設定是否支援縮放

// webSettings.setSupportZoom(false);// 設定是否支援變焦,僅支援雙擊縮放

webSettings.setNeedInitialFocus(false);// 設定是否可以訪問檔案

// webSettings.setBlockNetworkImage(true);// 載入圖片放在最後載入渲染

// webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//

// 設定緩衝模式

webSettings.setCacheMode(webSettings.LOAD_NO_CACHE);// 不使用緩衝

webView.addJavascriptInterface(new Scan2(),"mMap");// 這裡的名稱就是在頁面window.fxl.testFunction()所取的別名

webView.addJavascriptInterface(new Scan2(),"phone");// 這裡的名稱就是在頁面window.fxl.testFunction()所取的別名

//關鍵setGeolocationEnabled

webView.getSettings().setGeolocationEnabled(true);

}


private void setClient() {

webView.setWebChromeClient(new WebChromeClient() {

@Override

publicvoid onGeolocationPermissionsShowPrompt(String origin, 

android.webkit.GeolocationPermissions.Callback callback) {   

callback.invoke(origin,true, false);     

super.onGeolocationPermissionsShowPrompt(origin, callback);  

        } 

}

android webview 擷取Geolocation

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.