Java Code Examples for android.webkit.WebSettings#setGeolocationEnabled()

The following examples show how to use android.webkit.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: BaseWebView.java    From RichWebList 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(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);

	// this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
	// settings 的设计
}
 
Example 2
Source File: lua_web.java    From stynico with MIT License 6 votes vote down vote up
private void initWebViewSettings()
{
    WebSettings webSettings = wv_web.getSettings();
    //可以有缓存
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //设置支持页面js可用
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    //设置允许访问文件数据
    webSettings.setAllowFileAccess(true);
    //可以使用localStorage
    webSettings.setDomStorageEnabled(true);
    //可以有数据库
    webSettings.setDatabaseEnabled(true);
    //设置定位的数据库路径
    String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    webSettings.setGeolocationDatabasePath(dir);
    //启用地理定位
    webSettings.setGeolocationEnabled(true);
}
 
Example 3
Source File: HuPuWebView.java    From TLint with Apache License 2.0 5 votes vote down vote up
private void init() {
    ((MyApplication) getContext().getApplicationContext()).getApplicationComponent().inject(this);
    WebSettings settings = getSettings();
    settings.setBuiltInZoomControls(false);
    settings.setSupportZoom(false);
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setSupportMultipleWindows(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setDomStorageEnabled(true);
    settings.setCacheMode(1);
    settings.setUseWideViewPort(true);
    if (Build.VERSION.SDK_INT > 6) {
        settings.setAppCacheEnabled(true);
        settings.setLoadWithOverviewMode(true);
    }
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    String path = getContext().getFilesDir().getPath();
    settings.setGeolocationEnabled(true);
    settings.setGeolocationDatabasePath(path);
    settings.setDomStorageEnabled(true);
    this.basicUA = settings.getUserAgentString() + " kanqiu/7.05.6303/7059";
    setBackgroundColor(0);
    initWebViewClient();
    try {
        if (mUserStorage.isLogin()) {
            String token = mUserStorage.getToken();
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com",
                    "u=" + URLEncoder.encode(mUserStorage.getCookie(), "utf-8"));
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com",
                    "_gamesu=" + URLEncoder.encode(token, "utf-8"));
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_inKanqiuApp=1");
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_kanqiu=1");
            CookieSyncManager.getInstance().sync();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: BrowserView.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
public BrowserView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(getFixedContext(context), attrs, defStyleAttr);

    WebSettings settings = getSettings();
    // 允许文件访问
    settings.setAllowFileAccess(true);
    // 允许网页定位
    settings.setGeolocationEnabled(true);
    // 允许保存密码
    //settings.setSavePassword(true);
    // 开启 JavaScript
    settings.setJavaScriptEnabled(true);
    // 允许网页弹对话框
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    // 加快网页加载完成的速度,等页面完成再加载图片
    settings.setLoadsImagesAutomatically(true);
    // 本地 DOM 存储(解决加载某些网页出现白板现象)
    settings.setDomStorageEnabled(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // 解决 Android 5.0 上 WebView 默认不允许加载 Http 与 Https 混合内容
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    // 不显示滚动条
    setVerticalScrollBarEnabled(false);
    setHorizontalScrollBarEnabled(false);
}
 
Example 5
Source File: EditorInfoActivity.java    From LeisureRead with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView() {

  final WebSettings webSettings = mWebView.getSettings();
  webSettings.setJavaScriptEnabled(true);
  webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
  webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
  webSettings.setDomStorageEnabled(true);
  webSettings.setGeolocationEnabled(true);
  mWebView.getSettings().setBlockNetworkImage(true);
  mWebView.setWebViewClient(webViewClient);
  mWebView.requestFocus(View.FOCUS_DOWN);
  mWebView.getSettings().setDefaultTextEncodingName("UTF-8");
  mWebView.setWebChromeClient(new WebChromeClient() {

    @Override
    public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {

      AlertDialog.Builder b2 = new AlertDialog.Builder(EditorInfoActivity.this).setTitle(
          R.string.app_name)
          .setMessage(message)
          .setPositiveButton("确定", (dialog, which) -> result.confirm());

      b2.setCancelable(false);
      b2.create();
      b2.show();
      return true;
    }
  });
  mWebView.loadUrl(url);
}
 
Example 6
Source File: BaseWebView.java    From dcs-sdk-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void init(Context context) {
    this.setVerticalScrollBarEnabled(false);
    this.setHorizontalScrollBarEnabled(false);
    if (Build.VERSION.SDK_INT < 19) {
        removeJavascriptInterface("searchBoxJavaBridge_");
    }

    WebSettings localWebSettings = this.getSettings();
    try {
        // 禁用file协议,http://www.tuicool.com/articles/Q36ZfuF, 防止Android WebView File域攻击
        localWebSettings.setAllowFileAccess(false);
        localWebSettings.setSupportZoom(false);
        localWebSettings.setBuiltInZoomControls(false);
        localWebSettings.setUseWideViewPort(true);
        localWebSettings.setDomStorageEnabled(true);
        localWebSettings.setLoadWithOverviewMode(true);
        localWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        localWebSettings.setPluginState(PluginState.ON);
        // 启用数据库
        localWebSettings.setDatabaseEnabled(true);
        // 设置定位的数据库路径
        String dir = context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
        localWebSettings.setGeolocationDatabasePath(dir);
        localWebSettings.setGeolocationEnabled(true);
        localWebSettings.setJavaScriptEnabled(true);
        localWebSettings.setSavePassword(false);
        String agent = localWebSettings.getUserAgentString();

        localWebSettings.setUserAgentString(agent);
        // setCookie(context, ".baidu.com", bdussCookie);

    } catch (Exception e1) {
        e1.printStackTrace();
    }
    this.setWebViewClient(new BridgeWebViewClient());
}
 
Example 7
Source File: Tab2Fragment.java    From HelloActivityAndFragment with Apache License 2.0 5 votes vote down vote up
@SuppressLint("JavascriptInterface")
private void initWebView() {

    // Settings
    WebSettings settings = webView.getSettings();
    settings.setDefaultTextEncodingName("GBK");
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setGeolocationEnabled(true);
    // settings.setDisplayZoomControls(false);
    settings.setBuiltInZoomControls(true);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);

    settings.setDatabaseEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setAppCachePath(this.getContext().getCacheDir().getAbsolutePath());
    settings.setDisplayZoomControls(false);


    webView.requestFocus();

    webView.setWebViewClient(new WebViewClient() {
    });

    webView.setWebChromeClient(new WebChromeClient() {

    });

}
 
Example 8
Source File: RexxarWebViewCore.java    From rexxar-android with MIT License 5 votes vote down vote up
@TargetApi(16)
@SuppressLint("SetJavaScriptEnabled")
protected void setupWebSettings(WebSettings ws) {
    ws.setAppCacheEnabled(true);
    WebViewCompatUtils.enableJavaScriptForWebView(getContext(), ws);
    ws.setJavaScriptEnabled(true);
    ws.setGeolocationEnabled(true);
    ws.setBuiltInZoomControls(true);
    ws.setDisplayZoomControls(false);

    ws.setAllowFileAccess(true);
    if (Utils.hasJellyBean()) {
        ws.setAllowFileAccessFromFileURLs(true);
        ws.setAllowUniversalAccessFromFileURLs(true);
    }

    // enable html cache
    ws.setDomStorageEnabled(true);
    ws.setAppCacheEnabled(true);
    // Set cache size to 8 mb by default. should be more than enough
    ws.setAppCacheMaxSize(1024 * 1024 * 8);
    // This next one is crazy. It's the DEFAULT location for your app's cache
    // But it didn't work for me without this line
    ws.setAppCachePath("/data/data/" + getContext().getPackageName() + "/cache");
    ws.setAllowFileAccess(true);
    ws.setCacheMode(WebSettings.LOAD_DEFAULT);

    String ua = ws.getUserAgentString() + " " + Rexxar.getUserAgent();
    ws.setUserAgentString(ua);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        ws.setUseWideViewPort(true);
    }

    if (Utils.hasLollipop()) {
        ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
}
 
Example 9
Source File: HTML5WebView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
	mContext = context;		
	Activity a = (Activity) mContext;
	
	mLayout = new FrameLayout(context);
	
	mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(a).inflate(R.layout.custom_screen, null);
	mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.main_content);
	mCustomViewContainer = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.fullscreen_custom_content);
	
	mLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);

	mWebChromeClient = new MyWebChromeClient();
    setWebChromeClient(mWebChromeClient);
    
    setWebViewClient(new MyWebViewClient());
       
    // Configure the webview
    WebSettings s = getSettings();
    s.setBuiltInZoomControls(true);
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    s.setUseWideViewPort(true);
    s.setLoadWithOverviewMode(true);
    s.setSavePassword(true);
    s.setSaveFormData(true);
    s.setJavaScriptEnabled(true);
    
    // enable navigator.geolocation 
    s.setGeolocationEnabled(true);
    s.setGeolocationDatabasePath("/data/data/org.itri.html5webview/databases/");
    
    // enable Web Storage: localStorage, sessionStorage
    s.setDomStorageEnabled(true);
    
    mContentView.addView(this);
}
 
Example 10
Source File: HuPuWebView.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
private void init() {
    WebSettings settings = getSettings();
    settings.setBuiltInZoomControls(false);
    settings.setSupportZoom(false);
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setSupportMultipleWindows(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setDomStorageEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setUseWideViewPort(true);
    if (Build.VERSION.SDK_INT > 6) {
        settings.setAppCacheEnabled(true);
        settings.setLoadWithOverviewMode(true);
    }
    String path = getContext().getFilesDir().getPath();
    settings.setGeolocationEnabled(true);
    settings.setGeolocationDatabasePath(path);
    settings.setDomStorageEnabled(true);
    this.basicUA = settings.getUserAgentString() + " kanqiu/7.05.6303/7059";
    setBackgroundColor(0);
    initWebViewClient();
    setWebChromeClient(new HuPuChromeClient());
    try {
        if (SettingPrefUtils.isLogin()) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "u=" + SettingPrefUtils.getCookies());
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_gamesu=" + URLEncoder.encode(SettingPrefUtils.getToken(), "utf-8"));
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_inKanqiuApp=1");
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_kanqiu=1");
            CookieSyncManager.getInstance().sync();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 11
Source File: SystemWebViewEngine.java    From pychat with MIT License 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
Example 12
Source File: MainActivity.java    From SlimSocial-for-Facebook with GNU General Public License v2.0 4 votes vote down vote up
private void SetupWebView() {
        webViewFacebook = findViewById(webView);
        webViewFacebook.setListener(this, this);

        webViewFacebook.clearPermittedHostnames();
        webViewFacebook.addPermittedHostname("facebook.com");
        webViewFacebook.addPermittedHostname("fbcdn.net");
        webViewFacebook.addPermittedHostname("fb.com");
        webViewFacebook.addPermittedHostname("fb.me");

/*
        webViewFacebook.addPermittedHostname("m.facebook.com");
        webViewFacebook.addPermittedHostname("h.facebook.com");
        webViewFacebook.addPermittedHostname("touch.facebook.com");
        webViewFacebook.addPermittedHostname("mbasic.facebook.com");
        webViewFacebook.addPermittedHostname("touch.facebook.com");
        webViewFacebook.addPermittedHostname("messenger.com");
*/

        webViewFacebook.requestFocus(View.FOCUS_DOWN);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//remove the keyboard issue

        WebSettings settings = webViewFacebook.getSettings();

        webViewFacebook.setDesktopMode(true);
        settings.setUserAgentString("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
        settings.setJavaScriptEnabled(true);

        //set text zoom
        int zoom = Integer.parseInt(savedPreferences.getString("pref_textSize", "100"));
        settings.setTextZoom(zoom);

        //set Geolocation
        settings.setGeolocationEnabled(savedPreferences.getBoolean("pref_allowGeolocation", true));

        // Use WideViewport and Zoom out if there is no viewport defined
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);

        // better image sizing support
        settings.setSupportZoom(true);
        settings.setDisplayZoomControls(false);
        settings.setBuiltInZoomControls(true);

        // set caching
        settings.setAppCachePath(getCacheDir().getAbsolutePath());
        settings.setAppCacheEnabled(true);

        settings.setLoadsImagesAutomatically(!savedPreferences.getBoolean("pref_doNotDownloadImages", false));//to save data

        settings.setDisplayZoomControls(false);
    }
 
Example 13
Source File: WebView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
public WebView(Context context) {
	super(context);
	WebSettings settings = getSettings();

	if(Build.VERSION.SDK_INT >= 16) {
		settings.setAllowFileAccessFromFileURLs(true);
		settings.setAllowUniversalAccessFromFileURLs(true);
	}

	if (Build.VERSION.SDK_INT >= 19) {
		try {
			_evaluateJavascript = android.webkit.WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class);
		} catch(NoSuchMethodException e) {
			DeviceLog.exception("Method evaluateJavascript not found", e);
			_evaluateJavascript = null;
		}
	}

	settings.setAppCacheEnabled(false);
	settings.setBlockNetworkImage(false);
	settings.setBlockNetworkLoads(false);
	settings.setBuiltInZoomControls(false);
	settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
	settings.setDatabaseEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setDisplayZoomControls(false);
	}

	settings.setDomStorageEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setEnableSmoothTransition(false);
	}

	settings.setGeolocationEnabled(false);
	settings.setJavaScriptCanOpenWindowsAutomatically(false);
	settings.setJavaScriptEnabled(true);
	settings.setLightTouchEnabled(false);
	settings.setLoadWithOverviewMode(false);
	settings.setLoadsImagesAutomatically(true);

	if(Build.VERSION.SDK_INT >= 17) {
		settings.setMediaPlaybackRequiresUserGesture(false);
	}

	if(Build.VERSION.SDK_INT >= 21) {
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
	}

	settings.setNeedInitialFocus(true);
	settings.setPluginState(WebSettings.PluginState.OFF);
	settings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
	settings.setSaveFormData(false);
	settings.setSavePassword(false);
	settings.setSupportMultipleWindows(false);
	settings.setSupportZoom(false);
	settings.setUseWideViewPort(true);

	setHorizontalScrollBarEnabled(false);
	setVerticalScrollBarEnabled(false);
	setInitialScale(0);
	setBackgroundColor(Color.TRANSPARENT);
	ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT));
	setBackgroundResource(0);

	addJavascriptInterface(new WebViewBridgeInterface(), "webviewbridge");
}
 
Example 14
Source File: WebPlayerView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
public WebPlayerView(Context context, String viewId, JSONObject webSettings, JSONObject webPlayerSettings) {
	super(context);

	this.viewId = viewId;

	WebSettings settings = getSettings();

	if(Build.VERSION.SDK_INT >= 16) {
		settings.setAllowFileAccessFromFileURLs(false);
		settings.setAllowUniversalAccessFromFileURLs(false);
	}
	if (Build.VERSION.SDK_INT >= 19) {
		try {
			_evaluateJavascript = WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class);
		} catch(NoSuchMethodException e) {
			DeviceLog.exception("Method evaluateJavascript not found", e);
			_evaluateJavascript = null;
		}
	}

	settings.setAppCacheEnabled(false);
	settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
	settings.setDatabaseEnabled(false);

	settings.setDomStorageEnabled(false);
	settings.setGeolocationEnabled(false);
	settings.setJavaScriptEnabled(true);
	settings.setLoadsImagesAutomatically(true);

	settings.setPluginState(WebSettings.PluginState.OFF);
	settings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
	settings.setSaveFormData(false);
	settings.setSavePassword(false);

	setHorizontalScrollBarEnabled(false);
	setVerticalScrollBarEnabled(false);
	setInitialScale(0);
	setBackgroundColor(Color.TRANSPARENT);
	ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT));
	setBackgroundResource(0);

	setSettings(webSettings, webPlayerSettings);

	setWebViewClient(new WebPlayerClient());
	setWebChromeClient(new WebPlayerChromeClient());
	setDownloadListener(new WebPlayerDownloadListener());

	addJavascriptInterface(new WebPlayerBridgeInterface(viewId), "webplayerbridge");

	WebPlayerViewCache.getInstance().addWebPlayer(viewId, this);

	this.subscribeOnLayoutChange();
}
 
Example 15
Source File: ClassicWebViewProvider.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled") // We explicitly want to enable JavaScript
private void configureDefaultSettings(Context context, WebSettings settings) {
    settings.setJavaScriptEnabled(true);

    // Needs to be enabled to display some HTML5 sites that use local storage
    settings.setDomStorageEnabled(true);

    // Enabling built in zooming shows the controls by default
    settings.setBuiltInZoomControls(true);

    // So we hide the controls after enabling zooming
    settings.setDisplayZoomControls(false);

    // To respect the html viewport:
    settings.setLoadWithOverviewMode(true);

    // Also increase text size to fill the viewport (this mirrors the behaviour of Firefox,
    // Chrome does this in the current Chrome Dev, but not Chrome release).
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);

    // Disable access to arbitrary local files by webpages - assets can still be loaded
    // via file:///android_asset/res, so at least error page images won't be blocked.
    settings.setAllowFileAccess(false);
    settings.setAllowFileAccessFromFileURLs(false);
    settings.setAllowUniversalAccessFromFileURLs(false);

    final String appName = context.getResources().getString(R.string.useragent_appname);
    settings.setUserAgentString(buildUserAgentString(context, settings, appName));

    // Right now I do not know why we should allow loading content from a content provider
    settings.setAllowContentAccess(false);

    // The default for those settings should be "false" - But we want to be explicit.
    settings.setAppCacheEnabled(false);
    settings.setDatabaseEnabled(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(false);

    // We do not implement the callbacks - So let's disable it.
    settings.setGeolocationEnabled(false);

    // We do not want to save any data...
    settings.setSaveFormData(false);
    //noinspection deprecation - This method is deprecated but let's call it in case WebView implementations still obey it.
    settings.setSavePassword(false);
}
 
Example 16
Source File: MainActivity.java    From styT with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void initWebSettings() {

    WebSettings settings = sMm.getSettings();
    settings.setUserAgentString("" + SPUtils.get(MainActivity.this, "if_7", ""));//UA
    //支持获取手势焦点
    sMm.requestFocusFromTouch();
    //支持JS
    settings.setJavaScriptEnabled((Boolean) SPUtils.get(MainActivity.this, "if_1", true));
    //支持插件

    // settings.setPluginState(WebSettings.PluginState.ON);
    //设置适应屏幕
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    //支持缩放
    settings.setSupportZoom((Boolean) SPUtils.get(MainActivity.this, "if_3", false)); // 支持缩放
    //隐藏原生的缩放控件
    settings.setDisplayZoomControls(false);
    //支持内容重新布局
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.supportMultipleWindows();
    settings.setSupportMultipleWindows(false);
    //设置缓存模式
    settings.setGeolocationEnabled((Boolean) SPUtils.get(MainActivity.this, "if_2", true));//允许地理位置可用
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled((Boolean) SPUtils.get(MainActivity.this, "if_4", 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);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    settings.setLoadsImagesAutomatically(false);

    // settings.setNeedInitialFocus(true);
    //设置编码格式
    //settings.setDefaultTextEncodingName("UTF-8");

}
 
Example 17
Source File: SystemWebViewEngine.java    From keemob with MIT License 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
Example 18
Source File: SystemWebViewEngine.java    From keemob with MIT License 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
Example 19
Source File: SystemWebViewEngine.java    From countly-sdk-cordova with MIT License 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
Example 20
Source File: Main2Activity.java    From styT with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void initWebSettings() {

    WebSettings settings = sMm.getSettings();
    settings.setUserAgentString("" + SPUtils.get(Main2Activity.this, "if_7", ""));//UA
    //支持获取手势焦点
    sMm.requestFocusFromTouch();
    //支持JS
    settings.setJavaScriptEnabled((Boolean) SPUtils.get(Main2Activity.this, "if_1", true));
    //支持插件

    // settings.setPluginState(WebSettings.PluginState.ON);
    //设置适应屏幕
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    //支持缩放
    settings.setSupportZoom((Boolean) SPUtils.get(Main2Activity.this, "if_3", false)); // 支持缩放
    //隐藏原生的缩放控件
    settings.setDisplayZoomControls(false);
    //支持内容重新布局
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.supportMultipleWindows();
    settings.setSupportMultipleWindows(false);
    //设置缓存模式
    settings.setGeolocationEnabled((Boolean) SPUtils.get(Main2Activity.this, "if_2", true));//允许地理位置可用
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled((Boolean) SPUtils.get(Main2Activity.this, "if_4", 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);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    //支持自动加载图片
    if (Build.VERSION.SDK_INT >= 19) {
        settings.setLoadsImagesAutomatically((Boolean) SPUtils.get(Main2Activity.this, "if_5", true));//图片
    } else {
        settings.setLoadsImagesAutomatically(false);
    }
    // settings.setNeedInitialFocus(true);
    //设置编码格式
    //settings.setDefaultTextEncodingName("UTF-8");

}