In action
mWebView.LoadUrl(url); await Task.Delay(10000); if (!mWebView.IsShown | cliente.ErroReportado) { Toast t = Toast.MakeText(Android.App.Application.Context, "Erro ao acessar o servidor, verifique conexão, usuário e senha e tente novamente!", ToastLength.Long); t.SetGravity(GravityFlags.Center, 0, 0); t.Show(); OnCreate(null); } }
In webviewclient
class ViewClient : WebViewClient { MainActivity _activity; public int iTentativasLogin { get; private set; } public bool ErroReportado { get; private set; } public ViewClient(MainActivity activity) { _activity = activity; } public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm) { Toast t ; if (Usuario.Length == 0 | Senha.Length == 0) { t = Toast.MakeText(Android.App.Application.Context, "Usuário ou senha não preenchidos", ToastLength.Long); t.SetGravity(GravityFlags.Center, 0, 0); t.Show(); handler.Cancel(); ErroReportado = true; } else { iTentativasLogin++; if (iTentativasLogin < 4) { handler.Proceed(Usuario, Senha); } else { t = Toast.MakeText(Android.App.Application.Context, "Usuário ou senha incorretos", ToastLength.Long); t.SetGravity(GravityFlags.Center, 0, 0); t.Show(); handler.Cancel(); ErroReportado = true; } } } }
source share