Skip to content

Commit

Permalink
Set cookie to hide banner on first launch #111 #106
Browse files Browse the repository at this point in the history
  • Loading branch information
sakusaku3939 committed Jun 22, 2024
1 parent 44bccd1 commit cceb990
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/com/example/deeplviewer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ class MainActivity : AppCompatActivity() {
cookieManager.setAcceptThirdPartyCookies(webView, true)

// Load cookies from SharedPreferences
val sharedPreferences = getSharedPreferences("MyAppCookies", Context.MODE_PRIVATE)
val sharedPreferences = getSharedPreferences("DeepLCookies", Context.MODE_PRIVATE)
val savedCookie = sharedPreferences.getString("cookie", null)
if (savedCookie != null) {
cookieManager.setCookie(startUrl, savedCookie)
} else {
// Set cookie to hide banner
cookieManager.setCookie(
"https://www.deepl.com",
"privacySettings=%7B%22v%22%3A%221%22%2C%22t%22%3A1713052800%2C%22m%22%3A%22LAX%22%2C%22consent%22%3A%5B%22NECESSARY%22%2C%22PERFORMANCE%22%2C%22COMFORT%22%2C%22MARKETING%22%5D%7D"
);
}

webView.settings.javaScriptEnabled = true
Expand Down Expand Up @@ -110,7 +116,7 @@ class MainActivity : AppCompatActivity() {
val cookieManager = CookieManager.getInstance()
val cookies = cookieManager.getCookie(originUrl)
if (cookies != null) {
val sharedPreferences = getSharedPreferences("MyAppCookies", Context.MODE_PRIVATE)
val sharedPreferences = getSharedPreferences("DeepLCookies", Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()
editor.putString("cookie", cookies)
editor.apply()
Expand Down

0 comments on commit cceb990

Please sign in to comment.