B4J Question where is the Cookie in JDK 14?

Solution
Tested with Java 19 (which is the recommended SDK):
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private WebView1 As WebView
    Private manager As JavaObject
    Private handler As JavaObject
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    manager.InitializeNewInstance("java.net.CookieManager", Null)
    handler.InitializeStatic("java.net.CookieHandler").RunMethod("setDefault", Array(manager))
    Root.LoadLayout("MainPage")
    WebView1.LoadUrl("https://www.google.com")
End Sub

Private Sub Button1_Click
    Dim cookieStore As JavaObject=manager.RunMethodJO("getCookieStore",Null)...

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tested with Java 19 (which is the recommended SDK):
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private WebView1 As WebView
    Private manager As JavaObject
    Private handler As JavaObject
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    manager.InitializeNewInstance("java.net.CookieManager", Null)
    handler.InitializeStatic("java.net.CookieHandler").RunMethod("setDefault", Array(manager))
    Root.LoadLayout("MainPage")
    WebView1.LoadUrl("https://www.google.com")
End Sub

Private Sub Button1_Click
    Dim cookieStore As JavaObject=manager.RunMethodJO("getCookieStore",Null)
    Dim s As List= cookieStore.RunMethodJO("getCookies",Null)
    Log(s)
End Sub

Works fine.

Output:
(UnmodifiableRandomAccessList) [AEC=AVh_V2hH-CXmOMIDE2Xe_KaHZRWK6k29rDeI5U1RxO3av6HhYPXvRbCfnw, NID=524=XHKTxBadgxHQxuY9RqcO7jKniu1Y5imY4HPaArSWOgdngPCjbvy0fl_wEu165iuEDKp6Kro79zkwQKEEK9AxekwOze9MoQBNYSHFFAJHBcpUpFpe7cmUwz6Dyg1hF9kOUlBt92mmELEyUdsA2JjKGx8RSixQ-Nt4UXC1hSwyOa7d5cuRSs1WQN0d8brHyQBbwkl2NT62I2G6JJfleQ]
 
Upvote 0
Solution

Anno Jo

Member
wow, it's really a magic erel. it is working fine now.
I guess put this before root.loadlayout is the answer. Am I correct?
B4X:
    manager.InitializeNewInstance("java.net.CookieManager", Null)
    handler.InitializeStatic("java.net.CookieHandler").RunMethod("setDefault", Array(manager))
    Root.LoadLayout("MainPage")

Thank you so much Erel
 
Upvote 0
Top