Android WebView, err net::Name_Not_Resolved - android

I have tried searching through the docs and other forums but no success.
I have an android application that is simply a webView that opens up a website as soon as you open the app. However, when connecting to my website I receive an error, net::ERR_NAME_NOT_RESOLVED. Changed the loadUrl with a popular website like Google.com and it worked just fine.
My website works fine from Google Chrome, on dekstop, etc.. just not in WebView.. Can anyone help explain why?
On Another note, I am also trying to find a way to manually enter the dns settings, hoping this would resolve the matter. Any tips or pointing me down the right path is very much appreciated.
Thanks.

Did you set WebViewClient and get error net::ERR_NAME_NOT_RESOLVED from this method?
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Log.d(TAG, error.getDescription());
}
if yes, I've resolved this using this method
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Log.d(TAG, description);
}
the first method, I got an error even though the website fully loaded, my suspect is the first method too sensitive so if the website fails to load javascript or CSS or something, the first method returns the error too.

Related

Android webview load webPage error messaging/unsupported-browser

I develop an android application that has to open url in a webView.
the page open without any issues on the browser, but in my webView it opens a blank page and logs the following error in the logcat.
I/chromium: [INFO:CONSOLE(2)] "FirebaseError: Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser).", source: https://myWebsite/static/js/2.4d0092a9.chunk.js (2)
And here it is my code
#SuppressLint("SetJavaScriptEnabled")
private void setUpWebViewSettings() {
WebSettings websettings = regularWebView.getSettings();
websettings.setJavaScriptEnabled(true);
websettings.setDomStorageEnabled(true);
websettings.setAllowFileAccess(true);
websettings.setAppCacheEnabled(true);
websettings.setUseWideViewPort(true);
websettings.setLoadWithOverviewMode(true);
websettings.setSaveFormData(true);
}
private void setUpMuWebView() {
regularWebView.clearCache(true);
regularWebView.clearHistory();
setUpWebViewSettings();
regularWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap 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);
Log.d(TAG, error.toString());
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
});
regularWebView.loadUrl(<UrlToLoad>);
}
What should I do to load the page? and is there any suggested webView library that can help me to open the page inside my application?
The error message is not related to the blank page issue, your webView is unable to render the page because of cashing issue.
I had experienced with the same issue when I worked with a react.js team, and clean the cash and made a hard reload on my PC browser to be able to open the webPage on my app webView.
and here it is the steps to do it:
Open the URL on the browser on your PC.
press F12 to open the Firebug.
Long press on the refresh page.
select empty cash and hard reload
After that try to open the URL from your App WebView.
these steps fixed the issue for me, and it should fix the issue for you if it's a cashing issue, otherwise, you have to you customtabsintent or contact the page admin to investigate and fix the issue if you can contact him.
And the unsupported-browser error message appease because of using Firebase cloud messaging feature. The Firebase Cloud Messages API in the JavaScript SDK uses APIs which are only supported by a subset of modern browsers, and webView component is using chromium which is not supporting the Firebase cloud messaging. Check out this related thread for more details.

I have an error accessing DocuSign signing URL with Webview

I am currently testing the DocuSign API with the Demo Sandbox.
I have a WebAPI in C# which uses the DocuSign API. I create an enveloppe containing the document to sign and generate the recipient View URL.
I also have an Android App with a Webview which is supposed to get the generated URL to permit the user to sign the document.
When the webview loads the URL, the error ERR_CONNECTION_RESET occurs.
I precise that it works well using the Android Emulator but not with my phone connected in WI-FI.
Thanks in advance.
I copy/pasted the URL to my phone browser and it works. It's only within the App and the Webview that I can reach it.
I expect to reach the Docusign signing page related to my Document.
The WebView shows an ERR_CONNECTION_RESET
EDIT :
Here is some code
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest url) {
if((url.getUrl()).toString().equals(Constant.URL + "?event=signing_complete"))
{
/*Some code to redirect to other activity*/
return true;
}
else
{
Log.i("url",rep);
myWebView.loadUrl(rep);
return false;
}
}
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error){
//myWebView.loadUrl(rep);
Log.d("ERROR", error.getErrorCode());
}
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
Log.i("SSL", "SSL error");
handler.proceed();
}
});
[here is the result in the webview][1]
[1]: https://i.stack.imgur.com/yRuly.png
EDIT 2 :
If it can help, My .NET WEB API is hosted on my computer with Windows IIS and is connected to the network through Ethernet.
The Android device is connected via WI-FI to the same network.
I don't know if the error is because of the usage of SSL to access the signing page of Docusign.
I tried to replace the url of the webview by google.com and it worked fine.
It would be great if you added some code, so we can easily trace the error.
Have you tried adding
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
to your web view?
I finally solved my problem but still don't understand the reasons.
I manually uninstalled the application from the device.
I reinstalled it and it worked, just feels so stupid that I didn't try that at first...
"Have you tried turning it off and on again ?"

Handle iFrame errors inside of webview

I have a page that displays a news story, the page's content is loaded from a json response which is cached, the problem occurs when the uses is not connected to the internet and tries to access the story, the story loads correctly but the iFrame shows an ER_INTERNET_DISCONNECTED error.
We want to still be able to use the offline feature but if the iFrame has any error remove it from the page, is there anyway to do this ?
I've uploaded a screenshot if that helps
enter image description here
webView.setWebViewClient(new WebViewClient() {
#Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
// either load a new url, or show a popup to the user
webView.loadUrl("file:///android_asset/custom_error.html");
} });
You can decide for yourself what to do in the onReceivedError

How to prevent the user from going to the apps and continue with browser

In my mobile site I have links to other websites that also have apps. when my users click on the links they get options in Android (I don't know about iPhone) to go to the app or continue with the browser. How do I prevent the user from going to the apps and just cntinue with the browser after clicking my links without seeing this menu (browser/app)?
What you're asking is how to prevent the expected behavior of a webpage you load in your app. That's generally not good UI/UX design. But, to do so you would need to set a WebViewClient on your WebView and evaluate the url that is being loaded to see if it is for the download of an app:
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if (url.contains("play.google.com")) {
//handle alternate action here
}
}
#Override
public void onPageFinished(WebView view, String url){
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
});
That's something that's been set up on the 3rd party site, not something that's being done by the OS. There's no way to control the behavior of the browser after the user has left your web site.
For example LinkedIn will do this but Last Pass does not, even though they also have an app. This is something LinkedIn has chosen to do with their site; you can't do anything about that from your web site.

Find out if Android WebView is showing cached page

I'm making an Android application that, among other things, shows websites in a webview. As far as I understand, the webview automatically shows a cached version of the page if a connection can't be established.
Is there any way to find out if the page shown has been fetched from the server or cache?
Maybe even how old the cached page is.
This is to be able to notify the user if he/she is viewing old information.
You could try a hack - at first set WebView's cache mode to WebSettings.NO_CACHE and load the URL. Then, create a custom WebChromeClient like this:
final String urlToLoad = "http://www.my-url.com";
webview.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl)
{
if (view.getSettings().getCacheMode() == WebSettings.LOAD_NO_CACHE && urlToLoad.equals(failingUrl))
{
view.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
view.loadUrl(urlToLoad);
return;
}
else
if (urlToLoad.equals(failingUrl))
{
// cache failed as well, load a local resource as last resort
// or inform the user
}
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
webview.loadUrl(urlToLoad);
Since the WebView work like the browser the answer is no.
There are some hacky way to detect that situation.
Or an alternative solution would be preventing the page from being cached (see WebView documentation)

Categories

Resources