From 6de89cb5f5ef0269e349c1496b0a6ede839e0934 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 4 Jan 2022 14:11:43 -0600 Subject: Fixed NullPointerException for cookies --- .../main/java/org/traccar/manager/MainFragment.kt | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/org/traccar/manager/MainFragment.kt b/app/src/main/java/org/traccar/manager/MainFragment.kt index ecb93e3..981f3d9 100644 --- a/app/src/main/java/org/traccar/manager/MainFragment.kt +++ b/app/src/main/java/org/traccar/manager/MainFragment.kt @@ -54,19 +54,20 @@ class MainFragment : WebViewFragment() { CookieManager.getInstance().flush() } - val cookies = CookieManager.getInstance().getCookie(url) - if (cookies.contains("JSESSIONID") && !tokenSet) { - // Register token on server - if (PreferenceManager.getDefaultSharedPreferences(activity) - .contains(MainActivity.PREFERENCE_TOKEN) - ) { - val token = PreferenceManager.getDefaultSharedPreferences(activity) - .getString(MainActivity.PREFERENCE_TOKEN, "") - val code = "updateNotificationToken && updateNotificationToken('$token')" - Log.d("MainFragment", code) - Toast.makeText(activity, code, Toast.LENGTH_LONG).show() - webView.evaluateJavascript(code, null) - tokenSet = true + CookieManager.getInstance().getCookie(url)?.let { + if (it.contains("JSESSIONID") && !tokenSet) { + // Register token on server + if (PreferenceManager.getDefaultSharedPreferences(activity) + .contains(MainActivity.PREFERENCE_TOKEN) + ) { + val token = PreferenceManager.getDefaultSharedPreferences(activity) + .getString(MainActivity.PREFERENCE_TOKEN, "") + val code = "updateNotificationToken && updateNotificationToken('$token')" + Log.d("MainFragment", code) + Toast.makeText(activity, code, Toast.LENGTH_LONG).show() + webView.evaluateJavascript(code, null) + tokenSet = true + } } } } -- cgit v1.2.3