Because of the project needs, you need to embed the Web page in the app, log in using Nativie, and then save the cookie to WebView for free login. The method of synchronizing cookies to WebView has a large number of references on the web, and you can refer to the following code:
/*** sync cookie*/private void synccookie (Context context, string url) { try{    LOG.D ("Nat: webview.synccookie.url", url); Cookiesyncmanager.createinstance (context); cookiemanager cookiemanager = cookiemanager.getinstance (); cookiemanager.setacceptcookie (True); cookiemanager.removesessioncookie ();// removal cookiemanager.removeallcookie (); &nbSp; string oldcookie = cookiemanager.getcookie (URL); if (oldcookie != null) {          LOG.D ("Nat: webview.synccookieoutter.oldcookie", oldcookie); } StringBuilder sbCookie = new StringBuilder (); sbcookie.append ( String.Format ("jsessionid=%s", "input your jsessionid string")); sbcookie.append (String.Format (";d omain=%s", "INPUT YOUR domain string ")); Sbcookie.append (String.Format (";p ath=%s", "INPUt your path string ")); String cookievalue = sbcookie.tostring (); cookiemanager.setcookie (Url, cookievalue); cookiesyncmanager.getinstance (). Sync (); string newcookie = cookiemanager.getcookie (URL); if (newcookie != null) {                LOG.D ("Nat: WebView.syncCookie.newCookie ", newcookie); } }catch (exception e) {    LOG.E ("Nat: webview.synccookie failed", e.tostring ()); } }
Use the above method to sync cookies to webview so that you can browse the Web without logging in.
But in the actual use of the process found that the cookie is not saved successfully, each time will jump to the login page, tangled for a long time, and finally found that it is in the initialization of webview missing something important. You can refer to the following my Code settings webview.
/*** init webview settings* */ private void Initwebviewsettings () {// mywebview.getsettings (). SetSupportZoom (true);// mywebview.getsettings (). Setbuiltinzoomcontrols (True) ;// mywebview.getsettings (). Setdefaultfontsize (;// ) mywebview.getsettings (). Setloadwithoverviewmode (True); // settings can access files Mywebview.getsettings (). Setallowfileaccess (true); // If you have JavaScript on the page you are visiting, WebView must set up support javascript Mywebview.getsettings (). Setjavascriptenabled (True); Mywebview.getsettings (). Setuseragentstring (Myapplication.getuseragent ()); &Nbsp; mywebview.getsettings (). Setcachemode (Websettings.load_no_cache); mywebview.getsettings (). Setallowfileaccess (True); mywebview.getsettings (). Setappcacheenabled (True); mywebview.getsettings (). Setdomstorageenabled (True); mywebview.getsettings (). Setdatabaseenabled (true); }
Complete the above two steps, run the program again, you will find that the Web page will not be redirected to the login page.
The first use of the WebView control, originally thought very simple, but accidentally fell out of the pit, everyone careful.
Android WebView Save Cookie Login