I am using Cordova and Phonegap to create an android app for a web based project. I have a problem regarding the authentication, when I do an XMLHttpRequest in my JavaScript code the return status is 0. I think I need to override the onReceivedHttpAuthRequest to pass the credentials (in the browser's case a dialog pops up when you load the website).
I searched a lot for the answer, people seem to be using CordovaWebViewClient which seems to be deprecated. So I am not sure what I need to do with the latest cordova libraries that don't include that class because obviously the line below is wrong.
this.appView.setWebViewClient(new MyWebViewClient ());
Does anyone know what I need to do to be able to setup my WebViewClient correctly? I posted the code of the MainActivity class below.
public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
super.onCreate(savedInstanceState);
this.appView.setWebViewClient(new MyWebViewClient ());
super.loadUrl(launchUrl);
}
private class MyWebViewClient extends WebViewClient {
@Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
handler.proceed("username", "password");
}
}
}
The answer below doesn't work for me because I am using a CordovaWebView. Using WebView setHttpAuthUsernamePassword?