The problem of assigning value to WebView's password control using JS in Android

Source: Internet
Author: User
Tags error code

Use WebView analog login on Cnblogs's Android client, which will require the user's username and password to be uploaded to the WebView and then submitted, which tests all the normal mx3 Flyme3 and flyme4. However, on my htcG12 (MIUI4), and Samsung Note2 on the error.
The error code is:

The code is as follows Copy Code

Public void Loginbypassword (string username, string password) {
        mcurrentrt = Enumrequesttype.loginfinish;
        final String strjs = String.Format ("javascript: document.getElementById (' Tbusername '). Value= '%s ';d Ocument.getelementbyid (' Tbpassword '). value= '%s '; document.getElementById (' Form1 '). Submit (); ", username, password);
        Mweb.post (New Runnable () {
             public void Run () {
                 Mweb.loadurl (STRJS);
           }
       });
   }

Mweb.loadurl (STRJS), The Times is wrong, the content of the error is "android.view.windowmanager$badtokenexception:unable to add window--token null isn't For an application ".

The workaround is to set the MWeb settings without saving the password "Settings.setsavepassword (false);" The code is as follows:

  code is as follows copy code
@SuppressLint ( {"Setjavascriptenabled"})
private void Initialweb () {
    websettings settings = Mweb.getsettings ();
     Settings.setsavepassword (FALSE);
    Settings.setsaveformdata (false);
    settings.setjavascriptenabled (true);
    Settings.setblocknetworkimage (true);
    Mweb.addjavascriptinterface (New Jsinterface (), "ifobj");
    mweb.setwebviewclient (mblogwebclient);
}

For this reason, but not all of the errors of "Unable to add window--token null isn't for a application".

Related Article

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.