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

The following examples show how to use android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs() . 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: WebViewActivity.java    From Tok-Android with GNU General Public License v3.0 6 votes vote down vote up
private void initSetting() {
    WebSettings settings = mWebView.getSettings();
    settings.setAppCacheEnabled(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    String userAgent = settings.getUserAgentString();
    settings.setUserAgentString(
        userAgent + " TokAndroid/" + String.valueOf(BuildConfig.VERSION_NAME));
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccessFromFileURLs(false);
    settings.setAllowUniversalAccessFromFileURLs(false);
    settings.setDomStorageEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setDatabaseEnabled(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
}
 
Example 2
Source File: ExtendedWebView.java    From ForPDA with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
public void init() {
    mUiThread = Thread.currentThread();
    audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    addJavascriptInterface(this, IBase.JS_BASE_INTERFACE);
    WebSettings settings = getSettings();
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    settings.setBuiltInZoomControls(false);
    settings.setDefaultFontSize(16);
    settings.setTextZoom(100);
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setAllowContentAccess(true);
    settings.setAllowFileAccessFromFileURLs(true);
    settings.setAllowUniversalAccessFromFileURLs(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
    setRelativeFontSize(Preferences.Main.getWebViewSize(getContext()));
    setBackgroundColor(App.getColorFromAttr(getContext(), R.attr.background_base));
}
 
Example 3
Source File: JSWebView.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint({"SetJavaScriptEnabled", "NewApi", "ObsoleteSdkInt"})
public void initializeSettings(WebSettings settings) {
    settings.setJavaScriptEnabled(true);
    addJavascriptInterface(new JavaScriptUtil(), "DappJsBridge");
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        settings.setAppCacheMaxSize(Long.MAX_VALUE);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        settings.setEnableSmoothTransition(true);
    }
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        settings.setMediaPlaybackRequiresUserGesture(true);
    }

    WebView.setWebContentsDebuggingEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setLoadsImagesAutomatically(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setDatabaseEnabled(true);
    settings.setDisplayZoomControls(false);
    settings.setAllowContentAccess(true);
    settings.setAllowFileAccess(false);
    settings.setRenderPriority(WebSettings.RenderPriority.LOW);
    setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    settings.setDefaultTextEncodingName("utf-8");
    settings.setAllowFileAccessFromFileURLs(false);
    settings.setAllowUniversalAccessFromFileURLs(false);
    // 特别注意:5.1以上默认禁止了https和http混用,以下方式是开启
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
    }
}
 
Example 4
Source File: NinjaWebView.java    From Ninja with Apache License 2.0 5 votes vote down vote up
private synchronized void initWebSettings() {
    WebSettings webSettings = getSettings();
    userAgentOriginal = webSettings.getUserAgentString();

    webSettings.setAllowContentAccess(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);

    webSettings.setAppCacheEnabled(true);
    webSettings.setAppCachePath(context.getCacheDir().toString());
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setGeolocationDatabasePath(context.getFilesDir().toString());

    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    webSettings.setDefaultTextEncodingName(BrowserUnit.URL_ENCODING);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        webSettings.setLoadsImagesAutomatically(true);
    } else {
        webSettings.setLoadsImagesAutomatically(false);
    }
}
 
Example 5
Source File: HelpActivity.java    From CatVision-io-SDK-Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_help);
	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	setSupportActionBar(toolbar);

	try {
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setDisplayShowHomeEnabled(true);
	} catch (NullPointerException e) {
		e.printStackTrace();
	}

	// Web view
	WebView webView = (WebView)findViewById(R.id.mainWebView);
	WebSettings webSettings = webView.getSettings();
	webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
	// other
	webSettings.setJavaScriptEnabled(true);
	webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
	webSettings.setAllowFileAccessFromFileURLs(true);
	webSettings.setAllowUniversalAccessFromFileURLs(true);
	// important!
	webView.setWebViewClient(new WebViewClient());
	webView.loadUrl("file:///android_asset/help/index.html");
}
 
Example 6
Source File: AboutActivity.java    From CatVision-io-SDK-Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_about);
	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	setSupportActionBar(toolbar);

	try {
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setDisplayShowHomeEnabled(true);
	} catch (NullPointerException e) {
		e.printStackTrace();
	}

	// Web view
	WebView webView = (WebView)findViewById(R.id.mainWebView);
	WebSettings webSettings = webView.getSettings();
	webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
	// other
	webSettings.setJavaScriptEnabled(true);
	webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
	webSettings.setAllowFileAccessFromFileURLs(true);
	webSettings.setAllowUniversalAccessFromFileURLs(true);
	// important!
	webView.setWebViewClient(new MyViewClient());
	webView.loadUrl("file:///android_asset/about/index.html");
}
 
Example 7
Source File: WebViewActivity.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
    private void initWebSetting(){
        WebSettings webSetting = mWebView.getSettings();
        webSetting.setJavaScriptEnabled(true);
        //  WebSettings.LOAD_DEFAULT 如果本地缓存可用且没有过期则使用本地缓存,否加载网络数据 默认值
        //  WebSettings.LOAD_CACHE_ELSE_NETWORK 优先加载本地缓存数据,无论缓存是否过期
        //  WebSettings.LOAD_NO_CACHE  只加载网络数据,不加载本地缓存
        //  WebSettings.LOAD_CACHE_ONLY 只加载缓存数据,不加载网络数据
        //Tips:有网络可以使用LOAD_DEFAULT 没有网时用LOAD_CACHE_ELSE_NETWORK
        webSetting.setCacheMode(android.webkit.WebSettings.LOAD_NO_CACHE);
        webSetting.setAppCacheEnabled(true);    //开启H5(APPCache)缓存功能websettings.setAppCacheMaxSize(1024*1024*8);
        String appCachePath = this.getApplicationContext().getCacheDir().getAbsolutePath();
        webSetting.setAppCachePath(appCachePath);
        //开启 DOM storage API 功能 较大存储空间,使用简单
        webSetting.setDomStorageEnabled(true);
        //开启 Application Caches 功能 方便构建离线APP 不推荐使用
        webSetting.setAppCacheEnabled(true);
        //支持通过JS打开新窗口
        webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
        //视图适应窗口
//        webSetting.setUseWideViewPort(true);
//        webSetting.setLoadWithOverviewMode(true);
        webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        //允许 WebView 使用 File 协议
        webSetting.setAllowFileAccess(true);
        //允许webview对文件的操作
        webSetting.setAllowUniversalAccessFromFileURLs(true);
        webSetting.setAllowFileAccessFromFileURLs(true);
    }
 
Example 8
Source File: WebViewInitializer.java    From FastWaiMai with MIT License 5 votes vote down vote up
/**
 * 初始化传入的webView
 */
@SuppressLint("SetJavaScriptEnabled")
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public WebView initialWebView(WebView webView){
	webView.setHorizontalScrollBarEnabled(false);
	//不能纵向滚动
	webView.setVerticalScrollBarEnabled(false);
	//允许截图
	webView.setDrawingCacheEnabled(true);
	//屏蔽长按事件
	webView.setOnLongClickListener(new View.OnLongClickListener() {
		@Override
		public boolean onLongClick(View v) {
			return true;
		}
	});
	//初始化WebSettings
	final WebSettings settings = webView.getSettings();
	settings.setJavaScriptEnabled(true);
	final String ua = settings.getUserAgentString();
	settings.setUserAgentString(ua + "Latte");
	//隐藏缩放控件
	settings.setBuiltInZoomControls(false);
	settings.setDisplayZoomControls(false);
	//禁止缩放
	settings.setSupportZoom(false);
	//文件权限
	settings.setAllowFileAccess(true);
	settings.setAllowFileAccessFromFileURLs(true);
	settings.setAllowUniversalAccessFromFileURLs(true);
	settings.setAllowContentAccess(true);
	//缓存相关
	settings.setAppCacheEnabled(true);
	settings.setDomStorageEnabled(true);
	settings.setDatabaseEnabled(true);
	settings.setCacheMode(WebSettings.LOAD_DEFAULT);

	return webView;
}
 
Example 9
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 10
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 11
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 12
Source File: CordovaWebView.java    From bluemix-parking-meter with MIT License 4 votes vote down vote up
static void enableUniversalAccess(WebSettings settings) {
    settings.setAllowUniversalAccessFromFileURLs(true);
}
 
Example 13
Source File: CordovaWebView.java    From phonegapbootcampsite with MIT License 4 votes vote down vote up
static void enableUniversalAccess(WebSettings settings) {
    settings.setAllowUniversalAccessFromFileURLs(true);
}
 
Example 14
Source File: CordovaWebView.java    From phonegap-plugin-loading-spinner with Apache License 2.0 4 votes vote down vote up
static void enableUniversalAccess(WebSettings settings) {
    settings.setAllowUniversalAccessFromFileURLs(true);
}
 
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: 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 17
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 18
Source File: CordovaWebView.java    From wildfly-samples with MIT License 4 votes vote down vote up
static void enableUniversalAccess(WebSettings settings) {
    settings.setAllowUniversalAccessFromFileURLs(true);
}
 
Example 19
Source File: CordovaWebView.java    From reader with MIT License 4 votes vote down vote up
static void enableUniversalAccess(WebSettings settings) {
    settings.setAllowUniversalAccessFromFileURLs(true);
}
 
Example 20
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
}