WebView.setHttpAuthUsernamePassword () not working?

I am developing a part of an Android application that needs to use WebView to open a password protected site. I use SharedPreferences to specify a username and password when a user first logs in to the application. I tested the returned credentials, so I know that they are correct. When I run this in the emulator, the site says that I am unauthorized (although I am). Here is the code:

setContentView(R.layout.browser); WebView browser = (WebView) findViewById(R.id.browser); browser.getSettings().setJavaScriptEnabled(true); SharedPreferences credentials = getSharedPreferences("credentials", 0); browser.setHttpAuthUsernamePassword("example.com", "", credentials.getString("username", ""), credentials.getString("password", "")); browser.loadUrl("http://example.com"); 

So does anyone know why this will not test me? Should the line of the sphere that I put "" really be something?

0
source share
3 answers

You can use this:

 webview.setWebViewClient(new WebViewClient() { @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { handler.proceed("username", "password"); } }); 
+1
source

If the site uses NTLM auth, this will not work. Android does not support NTLM Auth. Fennec (firefox mobile) is the only Android browser I've seen that supports it, but its still in alpha.

0
source

Android announces support for NTLM. I do not know if this is part of WebView or just a browser.

https://code.google.com/p/android/issues/detail?id=4962

0
source

Source: https://habr.com/ru/post/923264/


All Articles