use of android.webkit.WebResourceError in project openremote by openremote.
the class MainActivity method initializeWebView.
protected void initializeWebView() {
LOG.fine("Initializing web view");
final WebAppInterface webAppInterface = new WebAppInterface(this);
webView.addJavascriptInterface(webAppInterface, "MobileInterface");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
webView.setLongClickable(false);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
// TODO should we ignore images?
if (request.getUrl().getLastPathSegment() != null && (request.getUrl().getLastPathSegment().endsWith("png") || request.getUrl().getLastPathSegment().endsWith("jpg") || request.getUrl().getLastPathSegment().endsWith("ico")))
return;
// invalid token. The web app will then start a new login.
if (request.getUrl().getLastPathSegment() != null && request.getUrl().getLastPathSegment().equals("token") && request.getMethod().equals("POST") && errorResponse.getStatusCode() == 400) {
webAppInterface.tokenService.clearToken();
return;
}
LOG.warning("Error requesting '" + request.getUrl() + "', response code: " + errorResponse.getStatusCode());
errorViewHolder.show(R.string.httpError, R.string.httpErrorExplain, true, true);
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
if (Boolean.parseBoolean(getString(R.string.SSL_IGNORE))) {
LOG.fine("Ignoring SSL certificate error: " + error.getPrimaryError());
// Ignore SSL certificate errors
handler.proceed();
} else {
LOG.severe("SSL error: " + error.getPrimaryError());
LOG.severe("SSL certificate: " + error.getCertificate());
errorViewHolder.show(R.string.httpError, R.string.httpErrorExplain, true, true);
}
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
// TODO should we ignore images?
if (request.getUrl().getLastPathSegment() != null && (request.getUrl().getLastPathSegment().endsWith("png") || request.getUrl().getLastPathSegment().endsWith("jpg") || request.getUrl().getLastPathSegment().endsWith("ico")))
return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Remote debugging sessions from Chrome trigger "ERR_CACHE_MISS" that don't hurt, but we should not redirect the view
if (isRemoteDebuggingEnabled() && error.getErrorCode() == ERROR_UNKNOWN) {
return;
}
// Remote debugging session from Chrome wants to load about:blank and then fails with "ERROR_UNSUPPORTED_SCHEME", ignore
if (request.getUrl().toString().equals("about:blank") && error.getErrorCode() == ERROR_UNSUPPORTED_SCHEME) {
return;
}
LOG.warning("Error requesting '" + request.getUrl() + "': " + error.getErrorCode());
}
errorViewHolder.show(R.string.fatalError, R.string.fatalErrorExplain, false, true);
}
});
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
String msg = "WebApp console (" + consoleMessage.sourceId() + ":" + consoleMessage.lineNumber() + "): " + consoleMessage.message();
switch(consoleMessage.messageLevel()) {
case DEBUG:
case TIP:
LOG.fine(msg);
break;
case LOG:
LOG.info(msg);
break;
default:
LOG.severe(msg);
}
return true;
}
});
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
String writePermission = Manifest.permission.WRITE_EXTERNAL_STORAGE;
if (ContextCompat.checkSelfPermission(context, writePermission) != PackageManager.PERMISSION_GRANTED) {
// Location permission has not been granted yet, request it.
ActivityCompat.requestPermissions((MainActivity) context, new String[] { writePermission }, WRITE_PERMISSION_REQUEST);
} else {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimetype);
// ------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
// ------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimetype));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
if (dm != null) {
Toast.makeText(getApplicationContext(), R.string.downloading_file, Toast.LENGTH_LONG).show();
dm.enqueue(request);
} else {
Toast.makeText(getApplicationContext(), R.string.error_downloading, Toast.LENGTH_LONG).show();
}
}
}
});
}
use of android.webkit.WebResourceError in project CCIP-Android by CCIP-App.
the class IRCFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_web, container, false);
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
webView = (WebView) view.findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
view.loadUrl(URL_NO_NETWORK);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
});
webView.setWebChromeClient(new WebChromeViewClient(progressBar));
webView.loadUrl(URL_IRC);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= 21) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
}
return view;
}
use of android.webkit.WebResourceError in project SmartNews by JavenLu.
the class NewsDetailsActivity method initView.
private void initView() {
WindowUtil.getInstance().setStatusBarTextAndIconDark(NewsDetailsActivity.this);
initCustomToolBar();
containerFrameLayout = findViewById(R.id.container);
fragmentManager = getSupportFragmentManager();
webView = findViewById(R.id.web_view);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
showErrorFragment();
}
});
}
use of android.webkit.WebResourceError in project collect by getodk.
the class WebViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close);
String url = getIntent().getStringExtra(ExternalWebPageHelper.OPEN_URL);
webView = (WebView) findViewById(R.id.webView);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
getSupportActionBar().setTitle(url);
progressBar.setVisibility(View.VISIBLE);
invalidateOptionsMenu();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
webView.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
getSupportActionBar().setTitle(view.getTitle());
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
progressBar.setVisibility(View.GONE);
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.setHorizontalScrollBarEnabled(false);
webView.loadUrl(url);
}
use of android.webkit.WebResourceError in project android by testpress.
the class RssFeedDetailActivity method displayPost.
@SuppressLint("SetJavaScriptEnabled")
private void displayPost() {
postDetails.setVisibility(View.VISIBLE);
title.setText(rssItem.getTitle());
date.setText(DateUtils.getRelativeTimeSpanString(rssItem.getPublishDate()));
WebSettings settings = content.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
settings.setSupportZoom(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
content.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
progressBar.setVisibility(View.GONE);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
UIUtils.openInBrowser(getApplicationContext(), url);
return true;
}
});
content.loadDataWithBaseURL("file:///android_asset/", getHeader() + rssItem.getDescription(), "text/html", "UTF-8", null);
}
Aggregations