如何在Android Java代码中获取JavaScript Cookie?

时间:2022-02-22 04:27:05

I have write cookie in JavaScript

我用JavaScript编写cookie

function setCookie(cname,cvalue){
   window.localStorage.setItem(cname, JSON.stringify(cvalue));
}

setCookie('test_cookie',123);


function getCookie(cname) {
    var cookieValue = window.localStorage.getItem(cname);
    if (cookieValue) {
        return JSON.parse(cookieValue);
    } else {
        return "";
    }
}

getCookie('test_cookie'); //Output 123

I have generate one cookie name is test_cookie and value is 123 I need to get this 123 cookie value in Java code.

我生成一个cookie名称是test_cookie,值为123我需要在Java代码中获得这个123 cookie值。

How to get my cookie value in Android Java?

如何在Android Java中获取我的cookie值?

2 个解决方案

#1


0  

This question might answer your problems.

这个问题可能会回答你的问题。

Communication between Android Java and Phonegap Javascript?

Android Java和Phonegap Javascript之间的通信?

You'll need to add a JavascriptInterface.

您需要添加JavascriptInterface。

#2


0  

you can find your answer here-

你可以在这里找到答案 -

yourWebViewVariable.getSettings().setJavaScriptEnabled(true);

for Android 3.1 just add this to your java file onLoadInit:

对于Android 3.1,只需将其添加到您的java文件onLoadInit:

CookieManager.setAcceptFileSchemeCookies(true); //This is the line that    
specifically makes it work so the other lines is optional

CookieManager cookieManager = CookieManager.getInstance();      
cookieManager.setAcceptCookie(true); cookieManager.acceptCookie();

#1


0  

This question might answer your problems.

这个问题可能会回答你的问题。

Communication between Android Java and Phonegap Javascript?

Android Java和Phonegap Javascript之间的通信?

You'll need to add a JavascriptInterface.

您需要添加JavascriptInterface。

#2


0  

you can find your answer here-

你可以在这里找到答案 -

yourWebViewVariable.getSettings().setJavaScriptEnabled(true);

for Android 3.1 just add this to your java file onLoadInit:

对于Android 3.1,只需将其添加到您的java文件onLoadInit:

CookieManager.setAcceptFileSchemeCookies(true); //This is the line that    
specifically makes it work so the other lines is optional

CookieManager cookieManager = CookieManager.getInstance();      
cookieManager.setAcceptCookie(true); cookieManager.acceptCookie();