コード例 #1
0
        private Task OnClearCookiesRequest()
        {
            if (Control == null || Control.Disposed)
            {
                return(Task.CompletedTask);
            }

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.LollipopMr1)
            {
                CookieManager.Instance.RemoveAllCookies(null);
                CookieManager.Instance.Flush();
            }
            else
            {
#pragma warning disable CS0618
                //CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
                CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(Context);
                cookieSyncMngr.StartSync();
                CookieManager cookieManager = CookieManager.Instance;
                cookieManager.RemoveAllCookie();
                cookieManager.RemoveSessionCookie();
                cookieSyncMngr.StopSync();
                cookieSyncMngr.Sync();
#pragma warning restore CS0618
            }
            _cookieDomains.Clear();
            return(Task.CompletedTask);
        }
コード例 #2
0
        public Task ClearCookiesAsync()
        {
            var context = Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.LollipopMr1)
            {
                System.Diagnostics.Debug.WriteLine("Clearing cookies for API >= LollipopMr1");
                CookieManager.Instance.RemoveAllCookies(null);
                CookieManager.Instance.Flush();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Clearing cookies for API < LollipopMr1");
#pragma warning disable CS0618 // Type or member is obsolete
                CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(context);
#pragma warning restore CS0618 // Type or member is obsolete
                cookieSyncMngr.StartSync();
                CookieManager cookieManager = CookieManager.Instance;
                cookieManager.RemoveAllCookie();
                cookieManager.RemoveSessionCookie();
                cookieSyncMngr.StopSync();
                cookieSyncMngr.Sync();
            }

            return(Task.FromResult(true));
        }
コード例 #3
0
 public void ClearCookies()
 {
     if ((int)Build.VERSION.SdkInt >= (int)Android.OS.BuildVersionCodes.LollipopMr1)
     {
         CookieManager.Instance.RemoveAllCookies(null);
         CookieManager.Instance.Flush();
     }
     else
     {
         CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(Context);
         cookieSyncMngr.StartSync();
         CookieManager cookieManager = CookieManager.Instance;
         cookieManager.RemoveAllCookie();
         cookieManager.RemoveSessionCookie();
         cookieSyncMngr.StopSync();
         cookieSyncMngr.Sync();
     }
 }
コード例 #4
0
        public void ClearCookies()
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.LollipopMr1)
            {
                CookieManager.Instance.RemoveAllCookies(null);
                CookieManager.Instance.Flush();
            }
            else
            {
#pragma warning disable CS0618 // Тип или член устарел
                CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(MainActivity.Instance.ApplicationContext);
#pragma warning restore CS0618
                cookieSyncMngr.StartSync();
                CookieManager cookieManager = CookieManager.Instance;
                cookieManager.RemoveAllCookie();
                cookieManager.RemoveSessionCookie();
                cookieSyncMngr.StopSync();
                cookieSyncMngr.Sync();
            }
        }
        void DeleteCookies(object sender, EventArgs e)
        {
            string domain = (string)sender;

            // TODO Don't remove all cookies or cache, but domain-specific
#if __ANDROID__
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                CookieManager.Instance.RemoveAllCookies(null);
                CookieManager.Instance.Flush();
            }
            else
            {
                CookieSyncManager manager = CookieSyncManager.CreateInstance(Forms.Context);
                manager.StartSync();

                CookieManager.Instance.RemoveAllCookie();
                CookieManager.Instance.RemoveSessionCookie();

                manager.StopSync();
                manager.Sync();
            }
#elif __IOS__
            var cache = Foundation.NSUrlCache.SharedCache;
            cache.RemoveAllCachedResponses();
            cache.DiskCapacity   = 0;
            cache.MemoryCapacity = 0;

            EvaluateJavascript("localStorage.clear();");

            var jar = Foundation.NSHttpCookieStorage.SharedStorage;

            foreach (var cookie in jar.Cookies)
            {
                if (cookie.Domain.Contains(domain))
                {
                    jar.DeleteCookie(cookie);
                }
            }
#endif
        }
コード例 #6
0
        private Task OnAddCookieRequested(System.Net.Cookie cookie)
        {
            if (Control == null || cookie == null || String.IsNullOrEmpty(cookie.Domain) || String.IsNullOrEmpty(cookie.Name))
            {
                return(Task.CompletedTask);
            }
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.LollipopMr1)
            {
                SetCookie(cookie);
                CookieManager.Instance.Flush();
            }
            else
            {
#pragma warning disable CS0618
                CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(Context);
                cookieSyncMngr.StartSync();
                SetCookie(cookie);
                cookieSyncMngr.StopSync();
                cookieSyncMngr.Sync();
#pragma warning restore CS0618
            }
            return(Task.CompletedTask);
        }
コード例 #7
0
        //private static void ScheduleAppRestart(Context context)
        //{
        //    Intent intent = context.PackageManager.GetLaunchIntentForPackage(context.PackageName);
        //    intent.PutExtra("logOut", true);
        //    intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask | ActivityFlags.NewTask);
        //    PendingIntent pendingIntent = PendingIntent.GetActivity(MainApplication.GetInstance().BaseContext, 0, intent, PendingIntentFlags.OneShot);
        //    AlarmManager mgr = (AlarmManager)MainApplication.GetInstance().BaseContext.GetSystemService(Context.AlarmService);
        //    mgr.Set(AlarmType.Rtc, JavaSystem.CurrentTimeMillis() + 1000, pendingIntent);
        //}

        public static void ClearWebViewCache(Context context)
        {
            var mWebView = new WebView(context);

            mWebView.ClearCache(true);
            mWebView.ClearHistory();

            if (Build.VERSION.SdkInt >= BuildVersionCodes.LollipopMr1)
            {
                CookieManager.Instance.RemoveAllCookies(null);
                CookieManager.Instance.Flush();
            }
            else
            {
                CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(context);
                cookieSyncMngr.StartSync();
                CookieManager cookieManager = CookieManager.Instance;
                cookieManager.RemoveAllCookie();
                cookieManager.RemoveSessionCookie();
                cookieSyncMngr.StopSync();
                cookieSyncMngr.Sync();
            }
        }
コード例 #8
0
        private async Task OnClearCookiesRequest()
        {
            if (Control == null)
            {
                return;
            }

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.LollipopMr1)
            {
                CookieManager.Instance.RemoveAllCookies(null);
                CookieManager.Instance.Flush();
            }
            else
            {
                //CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
                CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(Context);
                cookieSyncMngr.StartSync();
                CookieManager cookieManager = CookieManager.Instance;
                cookieManager.RemoveAllCookie();
                cookieManager.RemoveSessionCookie();
                cookieSyncMngr.StopSync();
                cookieSyncMngr.Sync();
            }
        }