문제

I have an Android application which has a login screen. Upon the click of login button I am launching a webview with cookies passed to it. So, I am able to see the contents of the webpage in the webview.

But when I click on the links of the webpage loaded, then the request is faling and from there webpage is not loading. How to pass cookies in such a way that after the login , I can traverse through any number of webpages relentlessly.

도움이 되었습니까?

해결책

Try This..

    WebView webview = new WebView(this);
    webview.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }
    });

    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(webview.getContext());
    cookieSyncManager.startSync();
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.removeSessionCookie();
    cookieManager.setCookie(URL, COOKIE);
    cookieSyncManager.sync();

    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl(URL);
    setContentView(webview);

다른 팁

You should not leave your WebView. Intercept the link and load the URL in your own WebView

  WebView webview = new WebView(this);      
      webview.setWebViewClient(new WebViewClient() {  
          @Override  
          public boolean shouldOverrideUrlLoading(WebView view, String url)  
          {  
               view.loadUrl(url);  
               return true;  
          }  
        });                 
      setContentView(webview);      
      webview.loadUrl(yourUrl);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top