private async Task <string> OnGetAllCookieRequestAsync() { if (Control == null || Element == null) { return(string.Empty); } var cookies = string.Empty; if (Control != null && Element != null) { string url = string.Empty; try { url = Control.Url; }catch (Exception e) { url = Element.BaseUrl; } if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.LollipopMr1) { CookieManager.Instance.Flush(); cookies = CookieManager.Instance.GetCookie(url); } else { CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(Context); cookieSyncMngr.StartSync(); CookieManager cookieManager = CookieManager.Instance; cookies = cookieManager.GetCookie(url); } } return(cookies); }
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); }
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)); }
private async Task <string> OnGetCookieRequestAsync(string key) { var cookie = default(string); if (Control != null && Element != null) { var url = string.Empty; try { url = Control.Url; } catch (Exception e) { url = Element.BaseUrl; } string cookieCollectionString; string[] cookieCollection; try { if (Build.VERSION.SdkInt >= BuildVersionCodes.LollipopMr1) { CookieManager.Instance.Flush(); cookieCollectionString = CookieManager.Instance.GetCookie(url); } else { CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(Context); cookieSyncMngr.StartSync(); CookieManager cookieManager = CookieManager.Instance; cookieCollectionString = cookieManager.GetCookie(url); } cookieCollection = cookieCollectionString.Split(new[] { "; " }, StringSplitOptions.None); foreach (var c in cookieCollection) { var keyValue = c.Split(new[] { '=' }, 2); if (keyValue.Length > 1 && keyValue[0] == key) { cookie = keyValue[1]; break; } } } catch (Exception e) { } } return(cookie); }
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(); } }
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 }
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); }
//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(); } }
private async Task <string> OnSetCookieRequestAsync(Cookie cookie) { if (Control != null && Element != null) { var url = new Uri(Control.Url).Host; if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.LollipopMr1) { CookieManager.Instance.SetCookie(url, cookie.ToString()); CookieManager.Instance.Flush(); } else { CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(Context); cookieSyncMngr.StartSync(); CookieManager cookieManager = CookieManager.Instance; cookieManager.SetCookie(url, cookie.ToString()); cookieManager.Flush(); } } var toReturn = await OnGetCookieRequestAsync(cookie.Name); return(toReturn); }
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(); } }