Java Code Examples for android.webkit.WebSettings#setJavaScriptCanOpenWindowsAutomatically()
The following examples show how to use
android.webkit.WebSettings#setJavaScriptCanOpenWindowsAutomatically() .
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: lua_web.java From stynico with MIT License | 6 votes |
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 2
Source File: FindGankDetailAty.java From myapplication with Apache License 2.0 | 6 votes |
private void fillGankDatas() { Intent intent = getIntent(); mGankResultBean = (SearchResultsBean) intent.getSerializableExtra("gankItemInfos"); mGankDescStr = mGankResultBean.getDesc(); mMarqueeTextView.setText(mGankDescStr); mGankUrlStr = mGankResultBean.getUrl(); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setLoadWithOverviewMode(true); webSettings.setAppCacheEnabled(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); webSettings.setSupportZoom(false); webSettings.setPluginState(WebSettings.PluginState.ON); mWebView.setWebChromeClient(new FindGankDetailAty.MyWebChromeClient()); mWebView.setWebViewClient(new FindGankDetailAty.MyWebViewClient()); mWebView.loadUrl(mGankUrlStr); }
Example 3
Source File: GoogleRecaptchaVerifyActivity.java From v9porn with MIT License | 6 votes |
private void initWebView() { WebSettings mWebSettings = webView.getSettings(); //启用JavaScript。 mWebSettings.setJavaScriptEnabled(true); mWebSettings.setUseWideViewPort(true); mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true); cookieManager = CookieManager.getInstance(); webView.setWebViewClient(new MyWebClient()); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { loadVerifyPageSuccess(); } super.onProgressChanged(view, newProgress); } }); cookieManager.setAcceptThirdPartyCookies(webView, true); if (BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); } }
Example 4
Source File: BaseWebView.java From RichWebList with Apache License 2.0 | 6 votes |
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 5
Source File: WebViewFragment.java From Xndroid with GNU General Public License v3.0 | 6 votes |
private void setWebView() { WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true);//如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小 webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小 webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。 webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放 webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件 webSettings.setAllowFileAccess(true); //设置可以访问文件 webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口 webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片 webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式 webSettings.setDomStorageEnabled(true); mWebView.setWebViewClient(new WebViewClient()); }
Example 6
Source File: FullScreenWebViewDialog.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
private void buildSetting(WebView webView) { webView.clearCache(true); webView.clearHistory(); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setDefaultTextEncodingName("utf-8");// 避免中文乱码 webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); webSettings.setJavaScriptEnabled(true); webSettings.setNeedInitialFocus(false); // webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); // webSettings.setBlockNetworkLoads(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);//1、提高渲染的优先级 // webSettings.setBlockNetworkImage(true);//把图片加载放在最后来加载渲染 webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); webSettings.setSupportZoom(false); }
Example 7
Source File: FullScreenWebViewDialog.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
private void buildSetting(WebView webView) { webView.clearCache(true); webView.clearHistory(); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setDefaultTextEncodingName("utf-8");// 避免中文乱码 webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); webSettings.setJavaScriptEnabled(true); webSettings.setNeedInitialFocus(false); // webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); // webSettings.setBlockNetworkLoads(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);//1、提高渲染的优先级 // webSettings.setBlockNetworkImage(true);//把图片加载放在最后来加载渲染 webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); webSettings.setSupportZoom(false); }
Example 8
Source File: Html5Activity.java From ClassSchedule with Apache License 2.0 | 5 votes |
/** * 多窗口的问题 */ private void newWin(WebSettings mWebSettings) { //html中的_bank标签就是新建窗口打开,有时会打不开,需要加以下 //然后 复写 WebChromeClient的onCreateWindow方法 mWebSettings.setSupportMultipleWindows(false); mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true); }
Example 9
Source File: AboutActivity.java From CatVision-io-SDK-Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 10
Source File: FindVideoDetailAty.java From myapplication with Apache License 2.0 | 5 votes |
private void fillVideoDatas() throws ParseException { Intent intent = getIntent(); mVideoResultsBean = (VideoResultsBean) intent.getSerializableExtra("videoItemInfos"); mVideoItemUrlStr = mVideoResultsBean.getUrl(); Log.i("TAG", "mVideoItemUrlStr: " + mVideoItemUrlStr); // mVideoItemDescStr = "『" + mVideoResultsBean.getDesc() + "』"; // mVideoItemPublishAtStr = "PublishedAt: " + // DateUtil.utc2LocalTime(mVideoResultsBean.getPublishedAt()); // mVideoItemCreateAtStr = "CreatedAt: " + // DateUtil.utc2LocalTime(mVideoResultsBean.getCreatedAt()); // mVideoItemSourceStr = "Source from: " + mVideoResultsBean.getSource(); // mVideoItemWhoStr = "Shared by: " + mVideoResultsBean.getWho(); // mVideoDescTv.setText(mVideoItemDescStr); // mVideoPublishedAtTv.setText(mVideoItemPublishAtStr); // mVideoCreateAtTv.setText(mVideoItemCreateAtStr); // mVideoSourceTv.setText(mVideoItemSourceStr); // mVideoWhoTv.setText(mVideoItemWhoStr); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setLoadWithOverviewMode(true); webSettings.setAppCacheEnabled(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); webSettings.setSupportZoom(false); webSettings.setPluginState(WebSettings.PluginState.ON); mWebView.setBackgroundColor(255); // 设置背景色 mWebView.getBackground().setAlpha(249); // 设置填充透明度 范围:0-255 mWebView.setWebChromeClient(new MyWebChromeClient()); mWebView.setWebViewClient(new MyWebViewClient()); mWebView.loadUrl(mVideoItemUrlStr); }
Example 11
Source File: OAuthActivity.java From mage-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_oauth); serverURL = getIntent().getStringExtra(EXTRA_SERVER_URL); oauthType = (OAuthType) getIntent().getSerializableExtra(EXTRA_OAUTH_TYPE); oauthStrategy = getIntent().getStringExtra(EXTRA_OAUTH_STRATEGY); oauthURL = String.format("%s/auth/%s/signin", serverURL, oauthStrategy); uuid = new DeviceUuidFactory(this).getDeviceUuid().toString(); progress = findViewById(R.id.progress); webView = (WebView) findViewById(R.id.webView); WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); webView.addJavascriptInterface(this, "Android"); webView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { progress.setVisibility(View.INVISIBLE); if (url.contains("/callback")) { webView.setVisibility(View.INVISIBLE); webView.loadUrl("javascript:Android.getLogin(JSON.stringify(login));"); } } }); webView.loadUrl(oauthURL); }
Example 12
Source File: HuPuWebView.java From TLint with Apache License 2.0 | 5 votes |
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 13
Source File: MainActivity.java From webTube with GNU General Public License v3.0 | 5 votes |
public void setUpWebview() { // To save login info CookieHelper.acceptCookies(webView, true); // Some settings WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(false); webSettings.setAllowFileAccess(false); webSettings.setDatabaseEnabled(true); String cachePath = mApplicationContext .getDir("cache", Context.MODE_PRIVATE).getPath(); webSettings.setAppCachePath(cachePath); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webView.setHorizontalScrollBarEnabled(false); webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); webView.setBackgroundColor(Color.WHITE); webView.setScrollbarFadingEnabled(true); webView.setNetworkAvailable(true); }
Example 14
Source File: HWWebView.java From RePlugin-GameSdk with Apache License 2.0 | 5 votes |
@SuppressLint("SetJavaScriptEnabled") @SuppressWarnings("deprecation") public HWWebView(Context context) { super(context); mMebView=this; this.mContext = context; int screenWidth = ((Activity) context).getWindowManager() .getDefaultDisplay().getWidth(); // 屏幕宽(像素,如:480px) int screenHeight = ((Activity) context).getWindowManager() .getDefaultDisplay().getHeight(); // 屏幕高(像素,如:800p) progressBar = new ProgressBar(context, null, android.R.attr.progressBarStyle); progressBar.setVisibility(View.GONE); AbsoluteLayout.LayoutParams progressBarParams = new AbsoluteLayout.LayoutParams( 60, 60, (screenWidth - 60) / 2, (screenHeight - 60) / 2); this.addView(progressBar, progressBarParams); WebSettings set = this.getSettings(); set.setSavePassword(false); set.setSaveFormData(false); set.setJavaScriptEnabled(true); set.setJavaScriptCanOpenWindowsAutomatically(true); this.setWebViewClient(new HWWebViewClient()); }
Example 15
Source File: MainActivity.java From webTube with GNU General Public License v3.0 | 5 votes |
public void setUpWebview() { // To save login info CookieHelper.acceptCookies(webView, true); // Some settings WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(false); webSettings.setAllowFileAccess(false); webSettings.setDatabaseEnabled(true); String cachePath = mApplicationContext .getDir("cache", Context.MODE_PRIVATE).getPath(); webSettings.setAppCachePath(cachePath); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webView.setHorizontalScrollBarEnabled(false); webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); webView.setBackgroundColor(Color.WHITE); webView.setScrollbarFadingEnabled(true); webView.setNetworkAvailable(true); }
Example 16
Source File: JSWebView.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@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 17
Source File: WebViewActivity.java From movienow with GNU General Public License v3.0 | 5 votes |
private void initWebSettings() { WebSettings webSettings = webViewT.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); webSettings.setDisplayZoomControls(false); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setAllowFileAccess(true); webSettings.setDefaultTextEncodingName("UTF-8"); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); webSettings.setDomStorageEnabled(true); webSettings.setAppCacheMaxSize(1024 * 1024 * 8); String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath(); webSettings.setAppCachePath(appCachePath); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int mDensity = metrics.densityDpi; 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); } }
Example 18
Source File: SystemWebViewEngine.java From countly-sdk-cordova with MIT License | 4 votes |
@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: MyWebView.java From DoraemonKit with Apache License 2.0 | 4 votes |
private void init(Context context) { if (!(context instanceof Activity)) { throw new RuntimeException("only support Activity context"); } else { this.mContainerActivity = (Activity) context; WebSettings webSettings = this.getSettings(); webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(false); webSettings.setLoadsImagesAutomatically(true); webSettings.setUseWideViewPort(true); webSettings.setBuiltInZoomControls(false); webSettings.setDefaultTextEncodingName("UTF-8"); webSettings.setDomStorageEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setJavaScriptCanOpenWindowsAutomatically(false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setWebContentsDebuggingEnabled(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webSettings.setMixedContentMode(0); } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { this.removeJavascriptInterface("searchBoxJavaBridge_"); this.removeJavascriptInterface("accessibilityTraversal"); this.removeJavascriptInterface("accessibility"); } mMyWebViewClient = new MyWebViewClient(); this.setWebViewClient(mMyWebViewClient); this.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress < 100) { showLoadProgress(newProgress); } else { hideLoadProgress(); } } }); addProgressView(); } }
Example 20
Source File: SystemWebViewEngine.java From lona with GNU General Public License v3.0 | 4 votes |
@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 }