Due to the requirements of the project to make the router login, some routes can directly open the Web login, there are some open login window
Our route is an open login window, I do not open the login windows when I write my own webview
The answer to search online is Webview.sethttpauthusernamepassword (host, realm, username, password) WebView add webchromeclient rewrite Onjsalert found that the above methods can not solve the problem with the browser open when the login box will pop up when I log in with Android WebView prompt login failure can not open the login box, At first I thought it was JS generated pop-up box test to WebView setwebchromeclient rewrite webchromeclient in the
public boolean Onjsalert (WebView view, string URL, string message, jsresult result) public boolean Onjsconfirm (WebView view, String URL, String message, jsresult result) public boolean Onjsprompt (WebView view, string URL, String message, String defaultvalue , jspromptresult result) public boolean Onjsbeforeunload (WebView view, string URL, string message, jsresult result) public boolean onjstimeout ()
found that none of the above methods have been executed. Then I compare Firefox, ie,google Chrome feeling is browser to do their own browser to open when prompted to enter the user name and password found in Webviewclient there is a method Onreceivedhttpauthrequest then view the source code
Public void onreceivedhttpauthrequest (WebView view, Httpauthhandler handler, string host, String realm) { handler.cancel () ;}
The discovery is a direct call to the Handler.cancel (); Add webviewclient override Onreceivedhttpauthrequest to WebView this method will stop in a blank page when logging in, wait for processing, And there's no way to prompt for login failure when you start to open directly and then view the parameters in Onreceivedhttpauthrequest there is a Httpauthhandler source default is the call to cancel () discovery There is also a method proceed (String Username, String password) and then when overriding onreceivedhttpauthrequest
Public void onreceivedhttpauthrequest (WebView view, Httpauthhandler handler, string host, String realm) { Handler.proceed ("admin", "admin"// ps:admin is my router's default account and password
And then just log in to my router, the problem has been resolved here
Onreceivedhttpauthrequest This method is also in the main thread, you can make your own login window here
Android-webview Routing Login 192.168.1.1