Android-webview Routing Login 192.168.1.1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.