Java Code Examples for com.tencent.smtt.sdk.WebSettings#setGeolocationEnabled()

The following examples show how to use com.tencent.smtt.sdk.WebSettings#setGeolocationEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: X5WebView.java    From TBSVideoPlay with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化webview设置
 */
private void initWebViewSettings() {
    WebSettings webSetting = this.getSettings();
    webSetting.setJavaScriptEnabled(true);
    webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
    webSetting.setAllowFileAccess(true);
    webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webSetting.setSupportZoom(true);
    webSetting.setBuiltInZoomControls(true);
    webSetting.setUseWideViewPort(true);
    webSetting.setSupportMultipleWindows(true);
    // webSetting.setLoadWithOverviewMode(true);
    webSetting.setAppCacheEnabled(true);
    // webSetting.setDatabaseEnabled(true);
    webSetting.setDomStorageEnabled(true);
    webSetting.setGeolocationEnabled(true);
    webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
    // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
    webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
}
 
Example 2
Source File: X5WebView.java    From polyvideo with Apache License 2.0 6 votes vote down vote up
private void initWebViewSettings() {
	WebSettings webSetting = this.getSettings();
	webSetting.setJavaScriptEnabled(true);
	webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
	webSetting.setAllowFileAccess(true);
	webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
	webSetting.setSupportZoom(true);
	webSetting.setBuiltInZoomControls(true);
	webSetting.setUseWideViewPort(true);
	webSetting.setSupportMultipleWindows(true);
	// webSetting.setLoadWithOverviewMode(true);
	webSetting.setAppCacheEnabled(true);
	// webSetting.setDatabaseEnabled(true);
	webSetting.setDomStorageEnabled(true);
	webSetting.setGeolocationEnabled(true);
	webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
	// webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
	webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
	// webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
	webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

	// this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
	// settings 的设计
}
 
Example 3
Source File: X5WebView.java    From Readhub with Apache License 2.0 6 votes vote down vote up
private void initWebViewSettings() {
	WebSettings webSetting = this.getSettings();
	webSetting.setJavaScriptEnabled(true);
	webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
	webSetting.setAllowFileAccess(true);
	webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
	webSetting.setSupportZoom(false);
	webSetting.setBuiltInZoomControls(false);
	webSetting.setUseWideViewPort(true);
	webSetting.setSupportMultipleWindows(true);
	webSetting.setAppCacheEnabled(true);
	webSetting.setDomStorageEnabled(true);
	webSetting.setGeolocationEnabled(true);
	webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
	webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
	webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

}
 
Example 4
Source File: X5WebView.java    From FastAndroid with Apache License 2.0 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void initWebViewSettings() {
    WebSettings webSetting = this.getSettings();
    webSetting.setJavaScriptEnabled(true);
    webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
    webSetting.setAllowFileAccess(true);
    webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webSetting.setSupportZoom(true);
    webSetting.setBuiltInZoomControls(true);
    webSetting.setUseWideViewPort(true);
    webSetting.setSupportMultipleWindows(true);
    // webSetting.setLoadWithOverviewMode(true);
    webSetting.setAppCacheEnabled(true);
    // webSetting.setDatabaseEnabled(true);
    webSetting.setDomStorageEnabled(true);
    webSetting.setGeolocationEnabled(true);
    webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
    // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
    webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
    // settings 的设计
}
 
Example 5
Source File: X5WebView.java    From CacheWebView with MIT License 6 votes vote down vote up
private void initWebViewSettings() {
    WebSettings webSetting = this.getSettings();
    webSetting.setJavaScriptEnabled(true);
    webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
    webSetting.setAllowFileAccess(true);
    webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webSetting.setSupportZoom(true);
    webSetting.setBuiltInZoomControls(true);
    webSetting.setUseWideViewPort(true);
    webSetting.setSupportMultipleWindows(true);
    // webSetting.setLoadWithOverviewMode(true);
    webSetting.setAppCacheEnabled(true);
    // webSetting.setDatabaseEnabled(true);
    webSetting.setDomStorageEnabled(true);
    webSetting.setGeolocationEnabled(true);
    webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
    // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
    webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
    // settings 的设计
}
 
Example 6
Source File: x5_MainActivity.java    From styT with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void initWebSettings() {

    WebSettings settings = sMm.getSettings();
    //sMm.setLayerType();
    sMm.setDrawingCacheEnabled(true);
    //支持获取手势焦点
    sMm.requestFocusFromTouch();
    //支持JS
    settings.setJavaScriptEnabled(true);
    //支持插件
    //settings.setUserAgentString("Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-us) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3 XiaoMi/MiuiBrowser/8.9.4");//UA

    // settings.setPluginState(WebSettings.PluginState.ON);
    //设置适应屏幕
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    //支持缩放
    settings.setSupportZoom(false); // 支持缩放
    //隐藏原生的缩放控件
    settings.setDisplayZoomControls(false);
    //支持内容重新布局
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.supportMultipleWindows();
    settings.setSupportMultipleWindows(false);
    //设置缓存模式
    settings.setGeolocationEnabled(true);//允许地理位置可用
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setAppCacheEnabled(true);
    settings.setAppCachePath(sMm.getContext().getCacheDir().getAbsolutePath());
    //settings.setRenderPriority(WebSettings.RenderPriority.HIGH);  //提高渲染的优先级
    //设置可访问文件
    settings.setAllowFileAccess(true);
    //当webview调用requestFocus时为webview设置节点
    settings.setNeedInitialFocus(true);

}
 
Example 7
Source File: WebViewFragment.java    From Dainty with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void setSettings(WebSettings setting) {
    //noinspection deprecation
    setting.setJavaScriptEnabled(true);
    setting.setJavaScriptCanOpenWindowsAutomatically(true);
    setting.setAllowFileAccess(true);
    setting.setSupportZoom(true);
    setting.setBuiltInZoomControls(true);   //允许放大缩小
    setting.setDisplayZoomControls(false);    //去掉放大缩小框
    setting.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    setting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    setting.setSupportMultipleWindows(false);

    setting.setGeolocationEnabled(true);   //允许启用地理定位
    setting.setGeolocationDatabasePath(getActivity().getDir("geolocation", 0).getPath());
    setting.setSaveFormData(true);  //支持保存自动填充的表单数据
    setting.setDomStorageEnabled(true);  //支持DOM缓存
    setting.setDatabaseEnabled(true);
    setting.setAppCacheEnabled(true);
    setting.setAppCacheMaxSize(Long.MAX_VALUE);
    setting.setAppCachePath(getActivity().getDir("dainty_cache", 0).getPath());

    // 全屏显示
    setting.setUseWideViewPort(true);
    setting.setTextZoom(Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getContext()).getString("text_size", "100")));

}
 
Example 8
Source File: WebviewActivity.java    From AndroidFrame with Apache License 2.0 4 votes vote down vote up
private void initWebview() {
    mWebView = findViewById(R.id.webview);
    mBridge = new WebViewJavascriptBridge(this, sHandler, mWebView);
    mWebView.addJavascriptInterface(mBridge, "AndroidWebViewJavascriptBridge");
    WebSettings webSetting = mWebView.getSettings();
    webSetting.setJavaScriptEnabled(true);
    webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
    webSetting.setAllowFileAccess(true);
    webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSetting.setSupportZoom(true);
    webSetting.setBuiltInZoomControls(true);
    webSetting.setUseWideViewPort(true);
    webSetting.setSupportMultipleWindows(true);
    // webSetting.setLoadWithOverviewMode(true);
    webSetting.setAppCacheEnabled(true);
    // webSetting.setDatabaseEnabled(true);
    webSetting.setDomStorageEnabled(true);
    webSetting.setGeolocationEnabled(true);
    webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
    // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
    webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
    // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
    webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
    String userAgent = webSetting.getUserAgentString() + " " + AGENG_STR
            + AGENG_STR_SUFFIX + "/" + getVersionName() + "/QD"
            + getQudaoName() + "/";
    webSetting.setUserAgentString(userAgent);
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView webView, String s) {
            InputStream fs = WebviewActivity.this.getResources().openRawResource(
                    R.raw.jsbridge_init);
            String jsbridgeInitScript = getLocalText(fs);
            String js1 = "javascript:var evtAndroidJSB = document.createEvent('Event');"
                    + "evtAndroidJSB.initEvent('AndroidWebViewJavascriptBridgeReady', false, false); "
                    + "document.dispatchEvent(evtAndroidJSB);";
            String js2 = "javascript: " + jsbridgeInitScript;
            if (android.os.Build.VERSION.SDK_INT <= 18) {
                mWebView.loadUrl(js1);
                mWebView.loadUrl(js2);
            } else {
                mWebView.evaluateJavascript(js1, null);
                mWebView.evaluateJavascript(js2, null);
            }
            super.onPageFinished(webView, s);
        }
    });
}
 
Example 9
Source File: x5_WebviewSelfAdaption.java    From stynico with MIT License 4 votes vote down vote up
public void getWebviewAdaption(WebView webView)
{
       WebSettings webSettings = webView.getSettings();
       webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
       webSettings.setUseWideViewPort(true);//关键点
	//启用地理定位
	webSettings.setDomStorageEnabled(true);
	webSettings.setDatabaseEnabled((Boolean) SPUtils.get(context, "if_4", true));//数据库
	webSettings.setGeolocationEnabled((Boolean) SPUtils.get(context, "if_2", true));//地理
	webSettings.setUserAgentString("" + SPUtils.get(context, "if_7", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-us) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3 XiaoMi/MiuiBrowser/8.9.4"));//UA
       webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
	webSettings.setDisplayZoomControls(false);
	webSettings.setLoadsImagesAutomatically((Boolean) SPUtils.get(context, "if_5", true));//图片
       webSettings.setJavaScriptEnabled((Boolean) SPUtils.get(context, "if_1", true)); // 设置支持javascript脚本
       webSettings.setAllowFileAccess(true); // 允许访问文件
       webSettings.setBuiltInZoomControls(true); // 设置显示缩放按钮
       webSettings.setSupportZoom((Boolean) SPUtils.get(context, "if_3", false)); // 支持缩放
       webSettings.setLoadWithOverviewMode(true);

       DisplayMetrics metrics = new DisplayMetrics();
       //getWindowManager().getDefaultDisplay().getMetrics(metrics);
       int mDensity = metrics.densityDpi;
	// Log.d("maomao", "densityDpi = " + mDensity);
       if (mDensity == 240)
	{
           webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
       }
	else if (mDensity == 160)
	{
           webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
       }
	else if (mDensity == 120)
	{
           webSettings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
       }
	else if (mDensity == DisplayMetrics.DENSITY_XHIGH)
	{
           webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
       }
	else if (mDensity == DisplayMetrics.DENSITY_TV)
	{
           webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
       }
	else
	{
           webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
       }


       webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);


   }