Setting Android WebView cookies from HTML file in resource directory

I am trying to set a cookie using javascript inside webview. The web view is loaded from the local resources directory, how it is done (where the page is a string such as "index.html")

engine.loadUrl("file:///android_asset/" + page);

I found that the same file is downloaded from the Internet (i.e. http://www.domain.com/index.html ), then the same file can set a cookie as expected.

Older versions of android allow cookies to be created in local files, but newer versions do not. I tested this and it works on Samsung Galaxy Ace, HTC Desire Z and eclipse emulators of lower SDK, but does not work on Samsung SIII and Samsung Tab 10.1.

I need to set a cookie to transfer data between pages in my webview; Saving search results for redisplay.

If anyone knows of any methods / hacks to get around this local file issue, I would really appreciate it. I have been doing this for about 8 weeks. I asked a simulation question that may be useful for further reading, but the problem is now identified and is a completely different question, so I ask about it here. Android Android cookie returns null

Thanks.

+4
source share
2 answers

, , - cookie localhost. cookie , , cookie . Android, .

-.

. : Android cookie Android null

+1

, , , ,

  • , cookie - Cordova WebView (, cookie ):

    CookieManager.getInstance().setCookie("/", "MyCookie=xxx");
    
  • JS cookie ( ), "" , :

    CookieManager.getInstance().getCookie("file://");
    

cookie, , .

, .

0

All Articles