Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to login in webview in android

I have an application in which I am loading a URL in android Webview. There is a login page in this URL. I am unable to login through android webview using the valid username/password but I can login using android browser.

When I click on login button it does not respond to it... when I leave the app and come back to it.. it's my account logged in.. Why is it so? Why is not logging in when clicking on it?

    package com.example.vishal.webapi;

   //packages import
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
   //packages for webclient
    import android.webkit.WebViewClient;

    public class MainActivity extends AppCompatActivity {

   //instance of webview

        private WebView webview;

       //url for webview
        String url="https://yadva.com:3335";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            webview =(WebView) findViewById(R.id.webView);
            webview.loadUrl(url);

           //gettin websittings
            WebSettings webSettings=webview.getSettings();

            webSettings.setJavaScriptEnabled(true);

          //**enabled dom storage**
            webSettings.setDomStorageEnabled(true);
          //enabling javascript
            webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
          //database enabled
            webSettings.setDatabaseEnabled(true);
          //setwebcclient
            webview.setWebViewClient(new WebViewClient());

        }
    }
///code finish

Help me where I made mistake, I don't know...I'm stuck here..

like image 362
Vishal Gupta Avatar asked Nov 01 '25 13:11

Vishal Gupta


2 Answers

try below

 webview =(WebView) findViewById(R.id.webView);
        // below line should be last
        //webview.loadUrl(url);

       //gettin websittings
        WebSettings webSettings=webview.getSettings();

        webSettings.setJavaScriptEnabled(true);

      //**enabled dom storage**
        webSettings.setDomStorageEnabled(true);
      //enabling javascript
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
      //database enabled
        webSettings.setDatabaseEnabled(true);
      //setwebcclient
        webview.setWebViewClient(new WebViewClient());



         webview.loadUrl(url);
like image 65
Sush Avatar answered Nov 04 '25 04:11

Sush


Try this

webview.setWebViewClient(new MyWebViewClient ());

private class MyWebViewClient extends WebViewClient {
@Override
public void onReceivedHttpAuthRequest(WebView view,
        HttpAuthHandler handler, String host, String realm) {

    handler.proceed("[email protected]", "mypassword");

}
}
like image 28
dindinii Avatar answered Nov 04 '25 05:11

dindinii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!