P
P
pesice43892021-01-17 17:01:38
Android
pesice4389, 2021-01-17 17:01:38

How to save cookies of visited sites in webView?

Hello!

package com.example.test

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebViewClient
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        webViewSetup()
    }
    @SuppressLint("SetJavaScriptEnabled")
    private fun webViewSetup() {
        wb_WebView.webViewClient = WebViewClient()
        wb_WebView.apply {
            loadUrl("https://test.ru")
            settings.javaScriptEnabled = true
        }
    }
    override fun onBackPressed() {
       if (wb_WebView.canGoBack()) wb_WebView.goBack() else super.onBackPressed()
    }
}


Such a problem is that when the application is closed, cookies are not saved. How can this be fixed?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question