Android : webview : getting error code -6 net::ERR_CONNECTION_REFUSED - android

I keep getting errorcode -6 and description net::ERR_CONNECTION_REFUSED on android webview in
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView webview =(WebView) this.findViewById(R.id.webView);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.setWebViewClient(new MyWebViewClient());//I only implemented onReceivedError to display the errors in logcat
webview.loadUrl("http://mydomainexample.com");// it loads http://google.com but throws error code = -6 for my doamin which works fine in any navigator
}
while the exact same url (example http://aaaaaaaaa.com) works well in any navigator, do webviews make connections differently from navigators?
What could be causing this issue?

Maybe due to cookie request by the website (see Android Webview error code -6) but please post your code. There is also a posting on https://github.com/ionic-team/capacitor/issues/1848

The issue was that the loaded webpage had a js file that, asynchronously, made a request to a port which was blocked on the server. I've tried removing that request and it worked

Related

Why the windows authentication works on emulator webview but not on device?

All. I am working on web view based android application, and need to access one URL which has got windows authentication (Negotiate, NTLM) protected.
I did some code and make it work on the emulator.
But unfortunately, It doesn't work on devices.
I tested with Samsung s8 (Android 9.0), Samsung Tab A (Android 8.1)
Below is the code that I tried to integrate a web view on my application.
As I mentioned, it correctly works on the emulator but not on a device
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = findViewById(R.id.activity_main_webview);
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDefaultTextEncodingName("utf-8");
// REMOTE RESOURCE
mWebView.loadUrl("https://palmerston.wheelers.co/account/logon");
mWebView.setWebViewClient(new MyWebViewClient());
}
--> MyWebViewClient
#Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
String username="123";
String userpass="123";
handler.proceed(username, userpass);
}
I wonder if there is any other configuration or what causes authentication stopping on device webview.
Please help me to solve this problem, if you have faced this kind of issue before.
Thank you.

Android emulator can't get api data threw website

I have frontend and backend ready and working on localhost. I am displaying the frontend website threw the android emulator:
public class MainActivity extends AppCompatActivity {
private WebView webview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview =(WebView)findViewById(R.id.webView);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webview.loadUrl("http://10.0.2.2:4200/mobile");
}
}
The problem is that emulator can't get the data from database or send request to api to recieve the data so that it's not displayed. How it looks on a website:
Once again the problem is straight with emulator. I tried building the frontend in production mode with no success. This issue looks strange to me because I am just "retranslating" the working website. Maybe I should declare a special permission or sth like that.
Android Studio Error:

phonegap function not working in webview

I am trying to build a simple app using webview but unable to get phonegap functions working when I use the webview class. If I use "super" then the phonegap function works fine. Excuse my odd vocabulary.
///////////////// JAVA //////////////////////////
public class MainStart extends DroidGap {
HTML5WebView mWebView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().sync();
mWebView = new HTML5WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new JavaScriptInterface(this), "MyAndroid");
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl("file:///android_asset/www/index.html"); // phonegap function does not work
super.loadUrl("file:///android_asset/www/index.html"); // phonegap function works here
}
}
///////////////// JAVASCRIPT //////////////////////////
function onDeviceReady(){
navigator.notification.alert("PhoneGap is working");
}
the WebView that PhoneGap sets up include a multitude of features which you are not even referencing in your own WebView - like the Javascript bridge - without it there's no way you can call Native code from within your html page!
may I ask why exactly are you trying to re-create your own WebView, instead of just using the standard supplied one?

WebView does not display loaded Html on some phones

I have a WebView in one of my Activities where I want to load a Html page. The page contains jquery-mobile and some html. So I do the following in my Activity :
mWebView=(WebView) findViewById(R.id.MyWebView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){
[...]
});
mWebView.loadUrl("http://www.mymobilepage.html");
The problem is that the page gets loaded and displayed on the emulator, and on a HTC Desire, but when I try to load it on a LG Optimus One nothing gets displayed. The events onPageStarted and onPageFinished both get fired in my WebViewClient but just a blank page is displayed, and also I don't have any errors in my LogCat.
Thanks in advance.
When onPageFinished is called, the page may not be completely rendered. The documentation states:
Notify the host application that a page has finished loading. This method is called only for main frame. When onPageFinished() is called, the rendering picture may not be updated yet. To get the notification for the new Picture, use onNewPicture(WebView, Picture).
However, note that onNewPicture is documented as deprecated and obsolete. I ask about a replacement/alternative here.
This should be a comment, but since there is a bit of code on it I've added as response.
Try changing default background to transparent and alerting as soon as the page is loaded, just to be sure that at least the html is being interpreted:
mWebView = (WebView) this.findViewById(R.id.webview);
mWebView.setBackgroundColor(0);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
mWebView.setWebViewClient(new WebViewClient(){
#Override
public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
view.loadUrl("javascript:(function() { alert('hello'); })()");
} });
and when loading the webpage:
mWebView.clearView();
mWebView.loadUrl("http://yourmobilepage.something/");
and let us know if something happened.
Try this:
webView.post(new Runnable() {
#Override
public void run() {
// Your code here...
}
});
Have you checked your html/js code with different versions on the emulator? Newer Android versions have newer versions of WebKit, that might be the problem.
I would also check if you have LogCat set to show Error messages only, or Debug+Info+Warning+Error messages. According to this, the javascript errors should show up as Debug messages.
I had a similar issue to this, I found that calling clearview and then reload seemed to clear it up -- as in:
mWebView.clearView();
mWebView.loadUrl("http://yourmobilepage.something/");
mWebView.reload();

how to run local web application in android webview

can anybody tell how to run the local webapplication using android webview
I want to run my own webpages in android using web view
Thanks
I'm guessing you want something like this:
private WebView mWebView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayoutWithAWebView);
mWebView = (WebView)findViewById(R.id.yourWebViewIdFromTheLayout);
mWebView.getSettings().setJavaScriptEnabled(true); // Enable JavaScript
mWebView.loadData(yourHtmlData, "text/html", "utf-8");
}
Hopefully, that at least points you in the right direction.
Also, I'd recommend reading the documentation on the WebView, it's pretty thorough.
Just run your application on the emulator, as you normally do (and be sure to have your computer connected to internet).

Categories

Resources